Sunday, 27 March 2016

Solution of URI 1142 :: PUM


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 N, a,b,c=1,d=4;
    scanf("%d", &N);
    for(a=1;a<=N;a++)
    {
        for(b=c;b<=d;b++)
        {
            if(b%4==0)
                printf("PUM\n");
            else
                printf ("%d ",b);
        }
        c+=4; d+=4;
    }
    return 0;
}

5 comments:

  1. #include
    int main()
    {
    int n,i,a=0;
    scanf("%d",&n);

    for(i=1; i<n*4; i++)
    {
    printf("%d ",i);
    a++;
    if(a==3)
    {
    printf("PUM\n");
    a=0;
    i=i+1;
    }
    }

    return 0;
    }

    ReplyDelete
  2. Using while

    #include

    int main()
    {
    int N, a, b, c, d;

    scanf("%d", &N);

    a = 0;
    b = 1;
    c = 2;
    d = 3;


    while(a < N)
    {
    printf("%d %d %d PUM\n", b, c, d);
    a++;
    b = b + 4;
    c = c + 4;
    d = d + 4;
    }

    return 0;

    }

    ReplyDelete
  3. #include
    int main()
    {
    int n,i,j,x=1,y=3;
    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
    for(j=x;j<=y;j++)
    {
    printf("%d ",j);
    }
    printf("PUM\n");
    x+=4;
    y+=3;
    }
    return 0;
    }

    ReplyDelete
  4. #include
    int main()
    {
    int n,i,j,k=1;

    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
    printf("%d %d %d PUM\n",k,k+1,k+2);
    k=k+4;

    }


    return 0;
    }

    ReplyDelete

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