Skip to main content

URI Online Judge Solution 1145 Logical Sequence 2


URI Online Judge Solution 1145 Logical Sequence 2 using C Programming Language.
Write an program that reads two numbers X and Y (X < Y). After this, show a sequence of 1 to y, passing to the next line to each X numbers.

Input

The input contains two integer numbers X (1 < X < 20) and Y (X < Y < 100000).

Output

Each sequence must be printed in one line, with a blank space between each number, like the following example.
Input SampleOutput Sample
3 99
1 2 3
4 5 6
7 8 9
10 11 12
...
97 98 99

Solution using C :

#include <stdio.h>
int main() {
    int x,y,i,j=0;
    scanf("%d%d",&x,&y);
    for(i=1; i<=y; i++)
    {
        j++;
        printf("%d",i);
        if(j==x || i == y)
        {
            printf("\n");
            j=0;
        }
        else
            printf(" ");
    }
    return 0;
}

Comments