Question

In C please! 4.20 LAB: Countdown until matching digits Write a program that takes in an...

In C please!

4.20 LAB: Countdown until matching digits Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer, and stopping when both output digits are identical. Ex: If the input is: 93 the output is: 93 92 91 90 89 88 Ex: If the input is: 77 the output is: 77 Ex: If the input is: 15 or any number not between 20 and 98 (inclusive), the output is: Input must be 20-98 For coding simplicity, follow each output number by a space, even the last one. Use a while loop. Compare the digits; do not write a large if-else for all possible same-digit numbers (11, 22, 33, …, 88), as that approach would be cumbersome for larger ranges.

#include <stdio.h>

int main(void) {

/* Type your code here. */

return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main() {
    int n, i;
    scanf("%d", &n);
    if (n < 20 || n > 98) {
        printf("Input must be 20-98");
    } else {
        i = n;
        while (1) {
            printf("%d ", i);
            if (i%10 == i/10) {
                break;
            }
            i--;
        }
    }
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
In C please! 4.20 LAB: Countdown until matching digits Write a program that takes in an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 22.23 LAB 9 C FALL 2019: Countdown until matching digits Write a program that takes in...

    22.23 LAB 9 C FALL 2019: Countdown until matching digits Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer, and stopping when both output digits are identical. Ex: If the input is: 93 the output is: 93 92 91 90 89 88 Ex: If the input is: 77 the output is: 77 Ex: If the input is: 15 or any value not between 20 and 98...

  • how to solve this on c++? Write a program that reads a five digits integer, then...

    how to solve this on c++? Write a program that reads a five digits integer, then swaps the unit position digit with the ten thousandth position digit, also swap the tenth position digit with the thousandth position digit. Print the new number For example if the number is 37846 then the new number is 64873. Sample input / output: nter a five digits integer The new form of the number 37846 is 64873

  • 3.16 LAB: Output range with increment of 10 Write a program whose input is two integers,...

    3.16 LAB: Output range with increment of 10 Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than...

  • Using Dev C++, write a program to solve the problem as stated below. Write a program...

    Using Dev C++, write a program to solve the problem as stated below. Write a program will input a single integer value (all input will be exactly 8 digits long) and will store pairs of digits as individual integer values. The program will display the five 2-digit numbers as well as the average of these, each on their own line. Use a switch statement to print out Grade: and then either A (>=90), B ([80..89]), C ([70..79]), D ([60..69]) or...

  • Write a program whose input is two integers, and whose output is the first integer

    5.20 (Ch 5) HW: Output range with increment of 10 Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer Ex: If the input is: -15 30 Then the output is: 15 -5 5 15 25 Ex: If the second integer is less than the first as in 20 5, the output is: Second integer can't be less than the...

  • write it in C++ please Exercise # 1 : The 10 digits are spelled out respectively...

    write it in C++ please Exercise # 1 : The 10 digits are spelled out respectively as follows: "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", and "Nine". Write a program that prompts the user to enter a one digit positive integer and prints the number of characters required to spell out the integer. For example, if the integer is 7 then it is spelled "Seven" which requires 5 characters. Sample input/ output: Enter a one digit number: 8...

  • Write a C program which calculates how many digits a number has and prints each digit...

    Write a C program which calculates how many digits a number has and prints each digit in reserve order with space in between(no space after the last digit). The number > 0 and has no more than 5 digits. (optional] It is better to write two functions. One is designed for printing number in reverse order and the other is for counting the number of digits. Given that the value of number (which is an int variable) is 12345, the...

  • Please help me with this program.You are to write a C++ program that will read in...

    Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...

  • use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

    use  JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....

  • IN JAVA Write a program that first gets a list of integers from input. The input...

    IN JAVA Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates a threshold. Output all integers less than or equal to that last threshold value. Assume that the list will always contain fewer than 20 integers. Ex: If the input is: 5 50 60 140 200 75 100 the output is: 50 60 75...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT