Search This Blog

Loading...

Generate Number Pattern Triangle C Program

//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

No comments:

Post a Comment