Program #2: Drawing Triangles - PROGRAM MUST BE IN C Write a program that asks t
ID: 639573 • Letter: P
Question
Program #2: Drawing Triangles - PROGRAM MUST BE IN C
Write a program that asks the user to enter an integer between 1 and 15. If the number entered is outside that range, your program should print out an error message and re-prompt for another number. (This is an input validation loop.) Once the user enters a number in the correct range, your program will print out two patterns of asterisks that look like the following. Note that the number provided by the user is equal to the height of the pattern.
Link to example result: https://www.dropbox.com/s/0vuqo5hdi7xqjvk/Untitled-1.jpg?dl=0
Explanation / Answer
#include <stdio.h>
int main()
{
int c,k, n;
while(1)
{
printf("Enter an integer between 1 and 15 ");
scanf("%d",&n);
if(n>=1&&n<=15)
break;
else
printf("Invalid input,must between 1 and 15 ,Re-try ");
}
printf("Pattens ");
for ( c = n ; c >=1 ; c-- )
{
for( k = 1 ; k <= c ; k++ )
printf("*");
printf(" ");
}
printf(" ");
for ( c = n ; c >=1 ; c-- )
{
for( k = c ; k < n ; k++ )
printf(" ");
for( k = 1 ; k <= c ; k++ )
printf("*");
printf(" ");
}
printf(" ");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.