** C not C++** Write a complete program that includes the following three tasks:
ID: 3888083 • Letter: #
Question
** C not C++**
Write a complete program that includes the following three tasks: Write a for loop to count and display integers starting at 0 and counting by 5's up through 100 (one per line) Write a do-while loop to output the countdown to the new year. The countdown starts at 10 and goes down to 1 (one per line), followed by "Happy New Year!" and a newline. Ask the user to enter a positive number, using the prompt "Enter a positive number: ". Then print a newline. Using a while loop, print out the message "You're doing great today!" the user selected number of times (once per line).
Explanation / Answer
Write a complete program that includes the following three tasks: Write a for loop to count and display integers starting at 0 and counting by 5's up through 100 (one per line)
Answer:
#include <stdio.h>
int main()
{
int i;
for(i=0;i<=100;i+=5) {
printf("%d ", i);
}
return 0;
}
Write a do-while loop to output the countdown to the new year. The countdown starts at 10 and goes down to 1 (one per line), followed by "Happy New Year!"
Answer:
#include <stdio.h>
int main()
{
int i=10;
do {
printf("%d ",i);
i--;
}while(i>0);
printf("Happy New Year! ");
return 0;
}
Ask the user to enter a positive number, using the prompt "Enter a positive number: ". Then print a newline. Using a while loop, print out the message "You're doing great today!" the user selected number of times (once per line).
Answer:
#include <stdio.h>
int main()
{
int i=1,n;
printf("Enter a positive number: ");
scanf("%d", &n);
while(i<=n) {
printf("You're doing great today! ");
i++;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.