Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Need C program to print triangle of character or number

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-02-2010
Member
 
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.

Reply With Quote
  #2  
Old 03-02-2010
Member
 
Join Date: May 2008
Posts: 2,383
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");}

}
}
Reply With Quote
  #3  
Old 03-02-2010
Member
 
Join Date: Feb 2008
Posts: 1,845
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");

}
Reply With Quote
  #4  
Old 03-02-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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.
Reply With Quote
  #5  
Old 03-02-2010
Member
 
Join Date: Apr 2008
Posts: 1,947
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");
}

}
Reply With Quote
  #6  
Old 17-09-2011
Member
 
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;
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 09:33 PM.