Back

Can Any one Please Explain The Logic Of This Printing Pattern Program 

Created 3 years ago
233 Views
2 Comments
SWATHIPRIYA
@SWATHIPRIYA
SWATHIPRIYA
@SWATHIPRIYAProfile is locked. Login

You a given a number N. You need to print the pattern for the given value of N.

for N = 2 the pattern will be 

2 2 1 1

2 1

for N = 3 the pattern will be 

3 3 3 2 2 2 1 1 1

3 3 2 2 1 1

3 2 1

void printPat(int n)

{

int i,j,k,m;

int t=n;

while(t--){

k=1;

j=n;

m=(t+1);

for(i=1;i<=(n*m)+n;i++){

if(k<=m){

printf("%d ",j);

k++;

}

else

{

k=1;

j--;

}

}printf("$");

}

}

Comments (2)
Please login to comment.