Search

C Program to print Number Triangle || C Programs

Like alphabet triangle, we can write the c program to print the number triangle. The number triangle can be printed in different ways.

Let's see the c example to print number triangle.


Code -


#include<stdio.h>   
#include<stdlib.h> 
int main(){  
 int i,j,k,l,n;    
system("cls");  
printf("enter the range=");    
scanf("%d",&n);    
for(i=1;i<=n;i++)    
{    
for(j=1;j<=n-i;j++)    
{    
printf(" ");    
}    
for(k=1;k<=i;k++)    
{    
printf("%d",k);    
}    
for(l=i-1;l>=1;l--)    
{    
printf("%d",l);    
}    
printf("\n");    
}    
return 0;  
}  

Output -

enter the range= 4
   1
  121
 12321
1234321 

enter the range= 7
      1
     121
    12321
   1234321
  123454321
 12345654321
1234567654321 
6 views0 comments

Related Posts

See All

Program of Random Number in C || C Programs

Code - #include <stdio.h> #include <conio.h> #include <stdlib.h> void main() { // use rand() function to generate the number printf (" The random number is: %d", rand()); pri

Getchar() function in C || C Programs

Code - #include <stdio.h> #include <conio.h> void main() { char c; printf ("\n Enter a character \n"); c = getchar(); // get a single character printf(" You have passed ")

  • 1024px-Telegram_logo.svg
  • download
  • YouTube