The document provides instructions for writing a C program that displays a Triforce pattern of a given height. The program must prompt the user to input a height between 2 and 20, output an error message for invalid heights, and print the Triforce using '/' characters bordered by spaces according to the input height.
Fostering Friendships - Enhancing Social Bonds in the Classroom
C PROGRAM- C! Write a program that displays a Triforce of a given size.docx
1. C PROGRAM. C!
Write a program that displays a Triforce of a given size.
•
The height will be given as a line of input to your program.
•
The height should be within the range of 2 to 20 inclusive.
•
If height is invalid or missing, output invalid height then quit.
Example 1
Example 2
Example 3
Example 4
Example 5
Solution
#include<stdio.h>
#include<conio.h>
int main()
{
2. int h;
printf(“Input the height of Triforce―);
scanf(“%d―,&h);
int count=0;
while(count< h)
{
for (int i=0; i<3; i++)
{
for (int k=0; j<k-i; k++)
{
printf(“ “);
}
}
for (int j=0; j<i*2+1; j++) {
printf(“/―);
}
printf(“ ―);
}
break;
return 0;
}