174,955 views
11 votes
11 votes
Write a program that takes in an integer in the range 10 to 100 as input. Your program should countdown from that number to 0, printing the count each of each iteration. After ten numbers have been printed to the screen, you should start a newline. The program should stop looping at 0 and not output that value.

I would suggest using a counter to count how many items have been printed out and then after 10 items, print a new line character and then reset the counter.

important: Your output should use " %3d " for exact spacing and a space before and after each number that is output with newlines in order to test correctly.

Ex: If the input is: 10
the output is: 10 9 8 7 6 5 4 3 2 1

Ex: If the input is: 20
the output is: 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

For coding simplicity, follow each output number by a space, even the last one. statement.

Use a while loop. You will need to use an if statement and some sort of decremented variable in your loop.

The skeleton code given in C programming:

#include

int main(void) {
int userNum = 0;
int counter = 0;
printf("Enter a number between 10 and 100:\\");
scanf("%d", &userNum);
if (userNum >= 10 && userNum <=100)
{
while( )
{
/* your code here */
}
}
printf("\\");

return 0;

User Aruna Tebel
by
2.6k points

1 Answer

21 votes
21 votes

Answer:

Program to perform above

Step-by-step explanation:

#include <stdio.h>

int main() {

int userNum = 0;

int counter = 0;

printf("Enter a number between 10 and 100:\\");

scanf("%d", &userNum);

if (userNum >= 10 && userNum <=100)

{

while(userNum > 0)

{

printf("%d\\", userNum);

userNum--;

}

} else

{

printf("Number is out of range");

}

printf("\\");

return 0;

}

User Raymond Law
by
2.5k points