I am writing a program in C to print following series.
1
121
12321
1234321
Below is my code which works perfectly fine but is there any change which i can make to make the program use less loops.
#include <stdio.h>
int main() {
int num, i, j, terms, x;
printf("ENTER NUMBER OF TERMS: ");
scanf("%d", &terms);
x = terms--;
for(num=1;num<=terms;num++){
for(i=1;i<=x;i++){
printf(" ");
}
for(i=1; i<=num; i++) {
printf("%d", i);
}
for(j=num-1 ; j>0; j--){
printf("%d", j);
}
printf("\n");
x--;
}
}
Aucun commentaire:
Enregistrer un commentaire