You are viewing a single comment's thread. Return to all comments →
int main() {
int n; scanf("%d", &n); //Printing 1st n rows for(int i = n; i > 0; i--) { //Printing top left triangle pattern if(n - i > 0) for(int k = 0; k < n - i; k++) printf("%d ", n-k); //Printing top middle triangle pattern for(int j = 2*i-1; j > 0; j--) printf("%d ", i); //Printing top right triangle pattern if (n-i > 0) for(int k = n - i; k > 0; k--) printf("%d ", n-k+1); printf("\n"); } //Printing last n-1 rows for(int i = 1; i < n; i++) { //Printing bottom left triangle pattern if(n - i > 0) for(int k = 0; k < n-i; k++) printf("%d ", n-k); //Printing bottom middle triangle pattern for(int j = 2*i-1; j > 0; j--) printf("%d ", i+1); //Printing bottom right triangle pattern if (n-i > 0) for(int k = n-i; k > 0; k--) printf("%d ", n-k+1); printf("\n"); } return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Printing Pattern Using Loops
You are viewing a single comment's thread. Return to all comments →
include
include
include
include
int main() {
}