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
#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; }
Get Answers For Free
Most questions answered within 1 hours.