Code For Alls..!

get the code!!

Monday, 4 September 2017

Pattern Printing N - Sequence 001

                                                          Pattern Printing N - Sequence 001

The program must accept an integer N and print the pattern as shown in the Example Input/Output.
Input Format:
The first line contains N.
Output Format:
N lines containing the pattern as shown in the Example Input/Output.
Boundary Conditions:
2 <=  N <= 100
Example Input/Output 1:
Input:
4
Output:
1 2 3 4
9 10 11 12
13 14 15 16
5 6 7 8
Example Input/Output 2:
Input:
7
Output:
1 2 3 4 5 6 7
15 16 17 18 19 20 21
29 30 31 32 33 34 35
43 44 45 46 47 48 49
36 37 38 39 40 41 42
22 23 24 25 26 27 28
8 9 10 11 12 13 14
C CODE:
#include<stdio.h>
#include <stdlib.h>

int main()
{
int n,i,j,k;
scanf("%d",&n);
for(i=0;i<n;i=i+2)
{
    k=n*i+1;
    for(j=0;j<n;j++)
    printf("%d ",k+j);
    printf("\n");
}
if(n%2==0)
i=n-1;
else
i=n-2;
while(i>-1)
{
    k=n*i+1;
    for(j=0;j<n;j++)
    printf("%d ",k+j);
    i=i-2;
    printf("\n");
}
}