In this tutorial, we will learn about C program to Inverted pyramid number pattern
This program displays various different inverted number Pyramid pattern using nested for loop in C programming language
program 1
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows,space=0; printf("Enter the number of rows"); scanf("%d",&rows);//taking numer of rows from user for(i=rows; i>=1; i--){ for each row //outer for loop for(j=1; j<=space; j++)//print space at the begining printf(" "); for(j=1; j<=i; j++)//print right side of pyramid printf("%d",j); for(j=i-1; j>=1; j--)//print right side of pyramid printf("%d",j); printf("\n"); space++; } getch(); return 0; }
When the above code is executed, it produces the following results:
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 6 5 4 3 2 1 1 2 3 4 5 6 5 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1
program 2
Program
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k; int rows,count=1,num; printf("Enter the number of rows you want\n"); scanf("%d",&rows); count=1; num=1+(rows-1)*2; for(i=1; i<=rows; ++i){//outer for loop,(parent) for(j=1; j<=count; ++j){//inner for loop(child) printf(" ");//this loop print space for pyramid } for(k=num; k>=1; --k){//inner for loop(child) printf("%d",i);//this loop print number for pyramid } count++; num=num-2; printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 8 8 9
program 3
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k,rows,counter,temp,num; printf("Enter number of rows you want: \n"); scanf("%d",&rows); printf("Here your pattern\n"); counter=1; temp=1+(rows-1)*2; for(i=1; i<=rows; i++){ num=1; for(j=1; j<=counter; j++) { printf(" ");//print space in beginning } for(k=temp; k>=1; k--){ printf("%d", num);//print number for pattern num++; } counter++; temp=temp-2; printf("\n"); } return 0; }
Enter number of rows you want: 5 Here your pattern 123456789 1234567 12345 123 1
Suggested for you
For loop in C language
For loop in Python language
Nested for loop in Java language
Nested for loop in C++ language
Nested for loop in Python language
Floyd’s triangle number pattern using for loop in C
Floyd’s triangle pattern using nested for loop in Java
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…