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

Write a program that prompts a user for an integer value in the range 0 to 32,76

ID: 440896 • Letter: W

Question

Write a program that prompts a user for an integer value in the range 0 to 32,767 and then prints the individual

digits of the numbers on a line with three spaces between the digits. The first line is to start with the leftmost

digit and print all five digits; the second line is to start with the second digit from the left and print four digits;

and so forth. For example, if user enters 1234, your program should print:


0 1 2 3 4

1 2 3 4

2 3 4

3 4

4

Explanation / Answer

/ Import input/output library #include // Main block int main (void) { // Declare ints int num, num0, num1, num2, num3, num4; int digit4, digit3, digit2, digit1, digit0; // Print a prompt printf("Please enter a number between or equal to 0 and 32767: "); // Get user input scanf("%d",&num); // Check if value outside of range if ((num < 0) || (num > 32767)) { printf("Outside of Range "); } // Value is inside of range else { // line 1 below num4 = num / 10000; digit4 = num4 % 10; printf("%d ", digit4); num3 = num / 1000; digit3 = num3 % 10; printf("%d ", digit3); num2 = num / 100; digit2 = num2 % 10; printf("%d ", digit2); num1 = num / 10; digit1 = num1 % 10; printf("%d ", digit1); num0 = num / 1; digit0 = num0 % 10; printf("%d ", digit0); // line 2 below num3 = num / 1000; digit3 = num3 % 10; printf(" %d ", digit3); num2 = num / 100; digit2 = num2 % 10; printf("%d ", digit2); num1 = num / 10; digit1 = num1 % 10; printf("%d ", digit1); num0 = num / 1; digit0 = num0 % 10; printf("%d ", digit0); // line 3 below num2 = num / 100; digit2 = num2 % 10; printf(" %d ", digit2); num1 = num / 10; digit1 = num1 % 10; printf("%d ", digit1); num0 = num / 1; digit0 = num0 % 10; printf("%d ", digit0); // line 4 below num1 = num / 10; digit1 = num1 % 10; printf(" %d ", digit1); num0 = num / 1; digit0 = num0 % 10; printf("%d ", digit0); // line 5 below num0 = num / 1; digit0 = num0 % 10; printf(" %d ", digit0); } system("pause"); 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