Logo 
Search:

C Programming Articles

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

Program t generate triangle as shown in output

Posted By: Gertrude Miller     Category: C Programming     Views: 4122

Program t generate triangle as shown in output.

Code for Program t generate triangle as shown in output in C Programming


#include<stdio.h>
    #include<conio.h>
    void main()
    {
        int i,n,j;
        char ch;
        clrscr();
        printf("\n Please Give The Value of N:  ");
        scanf("%d",&n);
        if(n>20)
        {
            printf("\n N MUST BE LESS THAN OR EQUAL TO 20 ");
            printf("\n OTHERWISE IT IS NOT DISPLAY AS PYRAMID");
            printf(" OR NOT FIT IN ");
        }
        else
        {
            for(i=1;i<=n;i++)
            {
                if(ch==90)
                ch=65;
                for(j=1;j<=n-i;j++)
                printf("  ");
                for(j=1,ch=87;j<=i;j++,ch++)
                {
                    if(ch==91)
                    ch=65;
                    printf(" %c  ",ch);
                }
                printf("\n");


            }
        }
        getch();    
    }


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




     Please Give The Value of N:  9


                 W
               W   X
             W   X   Y
           W   X   Y   Z
         W   X   Y   Z   A
       W   X   Y   Z   A   B
     W   X   Y   Z   A   B   C
   W   X   Y   Z   A   B   C   D
 W   X   Y   Z   A   B   C   D   E
  
Share: 


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

Gertrude Miller
Gertrude Miller author of Program t generate triangle as shown in output is from Frankfurt, Germany.
 
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!