Friday 15 April 2016

Solution of URI 1179 :: Array Fill IV


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c=0,d,e,f,g,h,i,j,l=0,m=0,x=0,n,p,par[5],impar[5],ara[15];
    for(b=0; b<15; b++)
        scanf("%d", &ara[b]);
    for(a=0; a<15; a++)
    {
        if(l==5)
        {
            for(n=0; n<5; n++)
                printf("impar[%d] = %d\n", n, impar[n]);
            l=0;
        }
        if(m==5)
        {
            for(p=0; p<5; p++)
                printf("par[%d] = %d\n", p, par[p]);
            m=0;
        }

        if(ara[a]%2!=0)
        {
            impar[c]=ara[a];
            ++c;
            l++;
            if(c==5) c=0;
        }
        if(ara[a]%2==0)
        {
            par[x]=ara[a];
            ++x;
            m++;
            if(x==5) x=0;
        }
    }
    for(i=0; i<l; i++)
            printf("impar[%d] = %d\n", i, impar[i]);
    for(j=0; j<m; j++)
            printf("par[%d] = %d\n", j, par[j]);
    return 0;
}

3 comments:

  1. thank you for your perfect solution

    ReplyDelete
  2. #include
    int main()
    {
    int par[5],impar[5],i,j=0,k=0,a,m;
    for(i=1; i<16; i++)
    {
    scanf("%d",&a);
    if(a%2==0)
    {
    par[j++]=a;
    if(j==5)
    {
    for(m=0; m<5; m++)
    printf("par[%d] = %d\n",m,par[m]);
    j=0;
    }
    }
    else
    {
    impar[k++]=a;
    if(k==5)
    {
    for(m=0; m<5; m++)
    printf("impar[%d] = %d\n",m,impar[m]);
    k=0;
    }
    }
    }
    for(i=0;i<k;i++)printf("impar[%d] = %d\n",i,impar[i]);
    for(i=0;i<j;i++)printf("par[%d] = %d\n",i,par[i]);
    return 0;
    }

    ReplyDelete
  3. #include
    int main()
    {
    int n[10],n2[10],n3[5],n4[5],i,e=0,o=0,e2=0,o2=0,a[15];
    for(i=0;i<15;i++)
    {
    scanf("%d", &a[i]);
    if(i<=9)
    {
    if(a[i]%2==0)
    {
    n[e]=a[i];
    e++;
    }
    else
    {
    n2[o]=a[i];
    o++;
    }
    }
    else
    {
    if(a[i]%2==0)
    {
    n3[e2]=a[i];
    e2++;
    }
    else
    {
    n4[o2]=a[i];
    o2++;
    }
    }
    }
    for(int j=0;j<e;j++)
    {
    printf("par[%d] = %d\n", j,n[j]);
    }
    for(int j=0;j<o;j++)
    {
    printf("impar[%d] = %d\n", j,n2[j]);
    }
    for(i=0;i<o2;i++)
    {
    printf("impar[%d] = %d\n", i,n4[i]);
    }
    for(i=0;i<e2;i++)
    {
    printf("par[%d] = %d\n", i,n3[i]);
    }
    }

    ReplyDelete

Note: only a member of this blog may post a comment.