Write a program that takes an integer from standard input and then displays a ro
ID: 3789037 • Letter: W
Question
Write a program that takes an integer from standard input and then displays a row of asterisks of length equal to the input or equal to 20, whichever is smaller. At the start of the program, prompt the user to input a number by printing the string "Input number of asterisks: ". If the user inputs a negative number, then do not print anything. If the user inputs a number larger than 20, only print 20 asterisks. Example input/output pairs arc provided below: Input: 3; Output: *** Input: -5: Output: Input: 20; Output: ******************** Input: 98; Output: ********************Explanation / Answer
#include <stdio.h>
int main(void)
{
int i;
int n;
printf("Input number of Asterisks:");
scanf("%d",&n);
if (n>20)
{
for(i=1;i<=20;i++)
{
printf("%c",'*');
}
}
else if(n>0 && n<20)
{
for(i=1;i<=n;i++)
{
printf("%c",'*');
}
}
else
{
printf("");
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.