Problem 26

7 comments on “Problem 26”


  • sakshi

    #include
    using namespace std;

    void swap(int* x,int* y)
    {
    int temp;
    temp=*x;
    *x=*y;
    *y=temp;
    }
    int main()
    {
    int arr[] = {1,9,8,4,0,0,2,7,0,6,0};
    int size = sizeof(arr)/sizeof(arr[0]);
    int i,j;

    for(i=0; i<size; i++)
    {
    if(arr[i]==0)
    {
    for( j=i+1; j<size; j++)
    {
    if(arr[j]!=0)
    {
    swap(arr[i],arr[j]);
    break;
    }
    }
    }
    cout<<arr[i]<<" ";
    }
    return 0;
    }


  • Mohd Saif

    #python easy code for this

    arr=[1,9,8,4,0,0,2,7,0,6,0]
    for i in arr:
    if(i==0):
    arr.remove(i)
    arr.append(i)
    print(arr)


  • Mohd Saif

    arr=[1,9,8,4,0,0,2,7,0,6,0]
    count=0

    for i in range(0,len(arr)):
    if(arr[i]!=0):
    arr[count]=arr[i]
    count=count+1
    while(count<len(arr)):
    arr[count]=0
    count=count+1

    print(arr)


  • rishabh trivedi

    #python
    def zero(arr):
    for i in arr:
    if i==0:
    arr.remove(i)
    arr.append(i)
    print(arr)
    arr=[]
    for i in range(7):
    a=int(input())
    arr.append(a)
    zero(arr)


  • Ayantika

    #include
    void main()
    {
    int count=0,j=0;
    int arr[]={12,56,0,1,2,3,0,9,7};
    int n=sizeof(arr)/sizeof(arr[0]);
    for(int i=0;i<n;i++)
    {
    if(arr[i]!=0)
    {
    arr[j]=arr[i];
    j++;
    }
    }
    count=n-j;
    while(count)
    {
    arr[j]=0;
    j++;
    count–;
    }
    printf("\n\n\n");
    for(int i=0;i<n;i++)
    printf("\t%d",arr[i]);
    }


  • Ravisankar ka

    //Java program

    public class NewClass9 {
    public static void main(String[] args) {
    int arr[]={5,4,6,0,1,2,12,0,0,98,7,8,9,0};
    int index=0;
    for(int i=0;i<arr.length;i++){
    if(arr[i]!=0){
    arr[index]=arr[i];
    index++;
    }
    }
    while(index<arr.length){
    arr[index]=0;
    index++;
    }
    for(int i=0;i<arr.length;i++)
    System.out.print(arr[i]+" ");
    }

    }