Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to generate triangle

Posted By: Jay Brown     Category: C Programming     Views: 3597

Write a Program to generate triangle.

Code for Program to generate triangle in C Programming

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j;
clrscr();
printf("\n Please Give The Value of N:  ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
printf("  ");
for(j=i;j>=0;j--)
printf(" %d",j);
for(j=1;j<=i;j++)
printf(" %d",j);
printf("\n");
}
getch();
}


--------------------------------- OUTPUT ---------------------------------




Please Give The Value of N:  9


                      0
                 1 0 1
               2 1 0 1 2
             3 2 1 0 1 2 3
              4 3 2 1 0 1 2 3 4
         5 4 3 2 1 0 1 2 3 4 5
       6 5 4 3 2 1 0 1 2 3 4 5 6
     7 6 5 4 3 2 1 0 1 2 3 4 5 6 7
   8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8
  
Share: 


Didn't find what you were looking for? Find more on Program to generate triangle Or get search suggestion and latest updates.

Jay Brown
Jay Brown author of Program to generate triangle is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!