Question

write a C program to find whether the given number of three digits is an integer...

write a C program to find whether the given number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is since 3**3 + 7**3 + 1**3 = 371.
Output:
Enter a number, or -999 to quit : 432
4**3 + 3**3 + 2**3 is not = 432
Enter a number, or -999 to quit : 371
3**3 + 7**3 + 1**3 is = 371

please use the for or do while loop only
Enter a number, or -999 to quit : -999

Homework Answers

Answer #1
#include <stdio.h>

int main() {
    int n, num, d1, d2, d3;
    do {
        printf("Enter a number, or -999 to quit : ");
        scanf("%d", &n);
        if (n != -999) {
            num = n;
            d1 = n % 10;
            n /= 10;
            d2 = n % 10;
            n /= 10;
            d3 = n % 10;
            if (d1 * d1 * d1 + d2 * d2 * d2 + d3 * d3 * d3 == num) {
                printf("%d**3 + %d**3 + %d**3 is = %d\n", d3, d2, d1, num);
            } else {
                printf("%d**3 + %d**3 + %d**3 is not = %d\n", d3, d2, d1, num);
            }
        }
    } while (n != -999);
    return 0;
}

Know the answer?
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
Similar Questions
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
Challenge 1 - SumDigits.java Write a program that reads an integer between 0 and 1000 and...
Challenge 1 - SumDigits.java Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 837, the sum of all digits is 18. Sample output: Enter an integer between 0 and 1000: 837 The sum of all digits in 837 is 18
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The...
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The program finds and displays the three digits in the number. The program also calculates and displays the sum of the three digits. A sample run is shown below: Enter a number between 100 and 999: 528 The three digits in the number are: 5 2 8 The sum of the three digits is: 15 Note: You must use integer division and modulo division to...
[10 marks] (SumDigits.java) Write code that asks the user to enter an integer between 100 and...
[10 marks] (SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The program finds and displays the three digits in the number. The program also calculates and displays the sum of the three digits. A sample run is shown below: Enter a number between 100 and 999: 528 The three digits in the number are: 5 2 8 The sum of the three digits is: 15
How to write a C++ program. Additive persistence is a property of the sum of the...
How to write a C++ program. Additive persistence is a property of the sum of the digits of an integer. The sum of the digits is found, and then the summation of digits is performed creating a new sum. This process repeats until a single integer digit is reached. Consider the following example: 1. The beginning integer is 1234 2. Sum its digits is 1+2+3+4 = 10 3. The integer is now 10 4. The sum of its digits is...
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even...
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even number and continue to do so until they enter the given QUIT condition. The prompt for the user to enter a number is written as follows: "Enter an even number or [QUIT] to quit:" The quitting condition in this case will be the number 999. If the number they entered was an even number, output the message "Good job!" Otherwise, output the message "[number]...
given an integer, write a program that displays the number as follows first line         all digits...
given an integer, write a program that displays the number as follows first line         all digits second line   all except first digit third line        all except first two digits ..... last line          the last digit ex) 5 6 7 8 6 7 8 7 8 8
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT