☞ C program to print following pattern.
1*2*3*10*11*12
4*5*8*9
6*7
#include<stdio.h>
int main() {
int i,j,k,lt,rt,n;
scanf("%d",&n);
lt=1;
k=n*n+1;
for(i=n;i>0;i--){
for(j=i;j<n;j++)
printf("%c%c",32,32);
for(j=1;j<=i;j++){
printf("%d*",lt++);
}
rt=k;
for(j=1;j<=i;j++){
printf("%d",rt++);
if(j<i) printf("*");
}
k=k-i+1;
printf("\n");
}
}
Sample Input
3
Sample Output
1*2*3*10*11*12
4*5*8*9
6*7
Test Program
1*2*3*10*11*12
4*5*8*9
6*7
#include<stdio.h>
int main() {
int i,j,k,lt,rt,n;
scanf("%d",&n);
lt=1;
k=n*n+1;
for(i=n;i>0;i--){
for(j=i;j<n;j++)
printf("%c%c",32,32);
for(j=1;j<=i;j++){
printf("%d*",lt++);
}
rt=k;
for(j=1;j<=i;j++){
printf("%d",rt++);
if(j<i) printf("*");
}
k=k-i+1;
printf("\n");
}
}
Sample Input
3
Sample Output
1*2*3*10*11*12
4*5*8*9
6*7
Test Program