Hi the following code needs to be in C please!! I am really having trouble with
ID: 3785757 • Letter: H
Question
Hi the following code needs to be in C please!! I am really having trouble with this problem. Thank you very much in advance!!
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 four patterns of asterisks that look like the following. Note that the number provided by the user is equal to the height of the pattern. Let's say the input value was 8. Then the output should be:Explanation / Answer
#include <stdio.h>
#include <conio.h>
int main() {
int i,j;
int num;
printf("Enter a number range between 1 and 15:");
scanf("%d",&num);
if(num>1 && num<15){
for (i=num; i>=1; i--) {
for (j=1; j<=i; j++) {
printf(" * ");
}
printf(" ");
}
}
getch();
}
*******patter-2*****
#include <stdio.h>
#include <conio.h>
int main() {
int i,j,k,pattern=1;
int num;
printf("Enter a number range between 1 and 15:");
scanf("%d",&num);
if(num>1 && num<15){
for (i=num; i>=1; i--) {
for (k=pattern; k>=0; k--) {
printf(" "); // only 1 space
}
for (j=i; j>=1; j--) {
printf("*");
}
pattern = pattern + 1;
printf(" ");
}
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.