Results 1 to 6 of 6

Thread: Need C program to print triangle of character or number

  1. #1
    Join Date
    Dec 2009
    Posts
    38

    Need C program to print triangle of character or number

    Hi Friend,

    I have to write one C program to print the triangle of any character or number, for example:

    a
    aa
    aaa
    aaaa
    aaaaa

    I have tried many code to achieve this, but nothing was helpful. If you posses C program code to triangle of character or number, please let me know that. I would appreciate you any help over this program.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Need C program to print triangle of character or number

    Hi,

    I have one c program which prints triangle of character "*". For this I have used nested for loop for to print character in triangular shape. Please refer following example:
    Code:
    #include<stdio.h>
    int main()
    {
    int ib,jb,kb;
    
    for(ib=1 ; ib<=8 ; ib++)
    {
    for (jb=7 ; jb>=1 ; jb--)
    printf(" ");
    
    {for(kb=1 ; kb<=ib ; kb=kb+1)
    printf("*");
    printf("\n");}
    
    }
    }

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Need C program to print triangle of character or number

    Hi friend,

    Why don't you try below given C program code to print triangle of number?
    Code:
    #define MAX 9
    int main()
    
    {
    int int_arrayV[MAX]= {1 2 3 4 5 6 7 8 9}; 
    int im, jm, km, odd, hm=0;
    for(km=0, im=0 odd=1; im<3; im++)
    
    {
    if(km=! 0)
    
    odd+=2;
    for(jm= k; (jm<km+odd)&&(hm<MAX);jm++)
    
    {
    printf(" dm " int_arrayV[jm]);
    
    hm++;
    
    }
    printf("\n");
    
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Need C program to print triangle of character or number

    I suggest you to use three for loop in program to print the triangle of character or number. These three for loop should nested to each other. The condition from the last for loop will executed only when the condition from the first loop checked as 'true'. Then use the ''\n' in the last for loop to print eh character or number to the next line. Please try this logic in your program and let me know it working for you or not.

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Need C program to print triangle of character or number

    Hi friend,

    Try below given program, and when you run this program it will show the triangle of character. I have defined the characters which are displayed as triangle at the stating of program code. Please use this code and let know if you are getting any error.
    Code:
    nt main()
    {
    char str[20] "ANIRBANPAUL";
    int XW=0, YW=0, ZW=0;
    
    ZW strlen(str);
    
    for(XW 0; XW < ZW; XW+ 2)
    {
    for(YW 0; YW < XW; YW++)
    {
    printf(" c" str[YW]);
    }
    printf("\n");
    }
    
    }

  6. #6
    Join Date
    Sep 2011
    Posts
    1

    Re: Need C program to print triangle of character or number

    #include<stdio.h>

    int main()
    {
    int i,j,k;
    scanf("%d",&k);

    for(i=1;i<=k;i++)
    {for(j=1;j<=i;j++)
    {printf("a");}
    printf("\n");}
    return 0;
    }

Similar Threads

  1. How to write program to generate a pascal triangle in java?
    By Aandaleeb in forum Software Development
    Replies: 7
    Last Post: 11-09-2011, 12:37 PM
  2. What is the program to print table of given number?
    By Roxy_jacob in forum Software Development
    Replies: 5
    Last Post: 04-09-2011, 10:40 PM
  3. How can I print any number or character using cout in C++
    By UseME in forum Software Development
    Replies: 5
    Last Post: 26-02-2010, 10:17 PM
  4. program to print prime factor of given number
    By teena_pansare in forum Software Development
    Replies: 4
    Last Post: 27-11-2009, 10:21 AM
  5. Want To Print Triangle In C++
    By vishodhan in forum Software Development
    Replies: 1
    Last Post: 08-01-2009, 09:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,647,666.04687 seconds with 17 queries