Color Triangle C Language Program with full code.This program creates a dynamic triangle based on user input and print message when tringle size exceeded.
#include<stdio.h>
#include<conio.h>
/* Girfa : Student Help
Color triangle example
for program visit :
http://girfahelp.blogspot.in/p/c-language.html
*/
void main()
{
int a,b,c,d=1,space=20;
clrscr();
printf("Enter size of triangle>> ");
scanf("%d",&c);
if(c<=11)
{
a=1;
while(a<=c)
{
b=1;
while(b<=space)
{
printf(" ");
b++;
}
b=1;
while(b<=d)
{
textcolor(b);
cprintf("*");
b++;
}
printf("\n");
a++;
d=d+2;
space--;
}
a=0;
while(a<=c)
{
b=1;
while(b<=space)
{
printf(" ");
b++;
}
b=1;
while(b<=d)
{
textcolor(b);
cprintf("*");
b++;
}
printf("\n");
a++;
d=d-2;
space++;
}
}
else
{
printf("Out of Range");
}
getch();
}
#include<stdio.h>
#include<conio.h>
/* Girfa : Student Help
Color triangle example
for program visit :
http://girfahelp.blogspot.in/p/c-language.html
*/
void main()
{
int a,b,c,d=1,space=20;
clrscr();
printf("Enter size of triangle>> ");
scanf("%d",&c);
if(c<=11)
{
a=1;
while(a<=c)
{
b=1;
while(b<=space)
{
printf(" ");
b++;
}
b=1;
while(b<=d)
{
textcolor(b);
cprintf("*");
b++;
}
printf("\n");
a++;
d=d+2;
space--;
}
a=0;
while(a<=c)
{
b=1;
while(b<=space)
{
printf(" ");
b++;
}
b=1;
while(b<=d)
{
textcolor(b);
cprintf("*");
b++;
}
printf("\n");
a++;
d=d-2;
space++;
}
}
else
{
printf("Out of Range");
}
getch();
}
No comments:
Post a Comment