Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write it in c not c++ Write a program that prints all the numbers that are betwe

ID: 3909011 • Letter: W

Question

Write it in c not c++

Write a program that prints all the numbers that are between 1 and a certain integer, either in ascending order or in descending order. The first input is a positive integer. The program will ist the numbers between I and that positive integer. The second input should be (1) to count up or (O) to count down What are the invalid cases for each input? If any input is invalid, the program should print an error message and terminate without printing any numbers The format of the numbers list should be with comas' and a 'space' separating the numbers and with a do' after the last number, as shown below. Enter a positive integer: 10 Enter up (1) or down (O):0 Counting down: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1.

Explanation / Answer

#include int main() { int n, dir, i; printf("Enter a positive integer: "); scanf("%d", &n); printf("Enter up (1) or down (0): "); scanf("%d", &dir); if(dir == 0) { dir = -1; } printf("Counting down: "); for(i = n; i != 0; i += dir) { printf("%d", i); if(i + dir == 0) { printf(". "); } else { printf(", "); } } return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote