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.
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");}
}
}
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");
}
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.
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");
}
}
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;
}