Table of Contents
In this tutorial, we will discuss the Pyramid triangle number Pattern in C Language using for loop
In the C Language, We can print various type of Pyramid shapes through nested for loop using number and special character
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int Noofrows; printf("Enter number of rows to be printed!n"); scanf("%d",&Noofrows); int row,colSpaces,colStar; for(row=1; row<=Noofrows; row++) { for(colSpaces=Noofrows-row; colSpaces>=1; colSpaces--) { printf(" "); } for(colStar=1; colStar<=row; colStar++) { printf("%d ",row); } printf("n"); } return 0; }
When the above code is executed it produced the following result
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int Noofrows; printf("Enter number of rows to be printed!n"); scanf("%d",&Noofrows); int row,colSpaces,colStar; for(row=1; row<=Noofrows; row++) { for(colSpaces=Noofrows-row; colSpaces>=1; colSpaces--) { printf(" "); } for(colStar=1; colStar<=row; colStar++) { printf("%d ",colStar); } printf("n"); } return 0; }
When the above code is executed it produced the following result
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int i,space,row,k,count,count1; k=0; count=0; count1=0; printf("Enter number of rowsn"); scanf("%d",&row); for(i=1; i<=row; ++i) { for(space=1; space<=row-i; ++space){ printf(" "); ++count; } while(k != 2*i-1) { if(count<=row-1) { printf("%d",(i+k-2*count1)); } else { ++count1; printf("%d",(i+k-2*count1)); } ++k; } count1=count=k=0; printf("n"); } return 0; }
When the above code is executed it produced the following result
Program 4
#include <stdio.h> #include <stdlib.h> int main() { int i, space, rows, m, count_x, count_y; m=0; count_x=0; count_y=0; printf("Enter number of rows: n"); scanf("%d",&rows); for(i=1; i<=rows; ++i) { for(space=1; space <= rows-i; ++space) { printf(" "); ++count_x; } while(m != 2*i-1) { if (count_x <= rows-1) { printf("%d ", i+m); ++count_x; } else { ++count_y; printf("%d ", (i+m-2*count_y)); } ++m; } count_y = count_x = m= 0; printf("n"); } return 0; }
When the above code is executed it produced the following result
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.