Logo 
Search:

C Programming Articles

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

Program to print triangle of numbers as shown in description

Posted By: Geldefsman Bakker     Category: C Programming     Views: 6979

Program to print triangle of numbers as shown below

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1

Code for Program to print triangle of numbers as shown in description in C Programming

#include<conio.h>
#include<stdio.h>

void main()
{
staticint a[100][100],i,j,d;
clrscr();

    printf("ENTER THE ELEMENT .....");
    scanf("%d",&d);

     for(i = 0;i < d; i++)
      {

     for(j = 0; j <= i; j++)
     {
        if(i==0 && j==0)
        {
         a[i][j] = 1;
        }
        else
        a[i][j] = a[i-1][j-1]  + a[i-1][j];
        printf("  %4d",a[i][j]);

     }

      printf("\n");
      }

     getch();
}

/*
**********
OUTPUT
**********

ENTER THE ELEMENT .....7
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1


*/
  
Share: 



Geldefsman Bakker
Geldefsman Bakker author of Program to print triangle of numbers as shown in description is from Leiden, Netherlands.
 
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!