Program to print pattern as shown in sample output.
Sample Input5
Sample Output
1
232
34543
4567654
567898765
Solution in | C | JAVA | PYTHON |
---|
#include<stdio.h>
int main() {
int n, row, col, space, k;
scanf("%d",&n);
for(row=1;row<=n;row++){
k = row;
for(space=1;space<=n-row;space++)
printf(" ");
for(col=1;col<=(2*row)-1;col++){
printf("%d",k);
if(col<row)
k++;
else
k--;
}
printf("\n");
}
return 0;
}
int main() {
int n, row, col, space, k;
scanf("%d",&n);
for(row=1;row<=n;row++){
k = row;
for(space=1;space<=n-row;space++)
printf(" ");
for(col=1;col<=(2*row)-1;col++){
printf("%d",k);
if(col<row)
k++;
else
k--;
}
printf("\n");
}
return 0;
}
Input
5
Output
1
232
34543
4567654
567898765
5
Output
1
232
34543
4567654
567898765