PLEASE HELP C++ Program #1 Write a program that asks the user to enter an intege
ID: 3698654 • Letter: P
Question
PLEASE HELP C++
Program #1 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 opportunity to write 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 pattem Let us say that the input value was 5. Then please print the following four patterns CS1336- Programming Fundamentals Page: 2 If the input value is 8, then the output should beExplanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Enter the no. between 1 to 15: ");
int n;
do{
scanf("%d",&n);
if(n>15||n<1)
printf("You Entered the wrong Input!!Please Enter the number between 1 to 15 ");
}while(n>15||n<1);
int i,j;
for(i=0;i<n;i++)
{
for(j=n-i;j>0;j--)
printf("*");
printf(" ");
}
printf(" ");
for(i=0;i<n;i++)
{
for(j=1;j<=i;j++)
printf(" ");
for(j=n-i;j>0;j--)
printf("*");
printf(" ");
}
printf(" ");
for(i=0;i<n;i++)
{
for(j=i;j<n-1;j++)
printf(" ");
for(j=1;j<=2*i+1;j++)
printf("*");
printf(" ");
}
printf(" ");
for(i=0;i<n-1;i++)
{
for(j=i;j<n-1;j++)
printf(" ");
printf("*");
for(j=1;j<=2*i-1;j++)
printf(" ");
if(i!=0)
printf("*");
printf(" ");
}
for(i=1;i<2*n;i++)
printf("*");
printf(" ");
do{
printf("Enter the odd no between 1 to 15: ");
scanf("%d",&n);
if(n%2==0||n>15||n<1)
printf("You Entered the wrong Input!!Please Enter the odd number between 1 to 15 ");
}while(n%2==0||n>15||n<1);
int k=n/2;
for(i=1;i<=n;i++)
printf("* ");
printf(" ");
int p=n-4;
for(i=0;i<k-1;i++)
{
for(j=1;j<=i+1;j++)
printf(" ");
printf("* ");
for(j=p;j>=1;j--)
printf(" ");
printf("* ");
printf(" ");
p=p-2;
}
k++;
for(i=0;i<k-1;i++)
{
for(j=i;j<k-1;j++)
printf(" ");
printf("* ");
for(j=1;j<=2*i-1;j++)
printf(" ");
if(i!=0)
printf("* ");
printf(" ");
}
for(i=1;i<=n;i++)
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.