133k views
1 vote
Special numeric has three digits and holds a property that it is exactly equal to summation of cubes from each digit. For example, 370 is an element named special numeric. 370 = 3 3 + 7 3 + 0 3 . Write a C program to explore these special integer numbers from 100 to 999 and display all of them on screen. You can use for loop. Name your program f

User Greywire
by
4.6k points

1 Answer

4 votes

Answer:

The following code is written in C programming language:

#include <stdio.h> //header file

int main() //main method

{

int n, t, digit1, digit2, digit3; // set integer variables

// print message

printf("Print all Special integer numbers between 100 and 999:\\");

n = 100; //initialize value in variable "n"

while (n <= 999) //set while loop

{

digit1 = n - ((n / 10) * 10);

digit2 = (n / 10) - ((n / 100) * 10);

digit3 = (n / 100) - ((n / 1000) * 10);

t = (digit1 * digit1 * digit1) + (digit2 * digit2 * digit2) + (digit3 * digit3 * digit3);

if (t == n) //set if statement

{

printf("\\ Special integer number is: %d", t); //print an output

}

n++;

}

}

Output:

Print all Special integer numbers between 100 and 999:

Special integer number is: 153

Special integer number is: 370

Special integer number is: 371

Special integer number is: 407

Step-by-step explanation:

Here, we set the header file "stdio.h".

Then, we define integer type "main()" function.

Then, we set five integer type variable "n", "t", "digit1", "digit2", "digit3".

Then, we the print message by print() method and initialize a value to variable "n" to 100.

Then, we set the while loop which starts from 100 and stops at 999 and if the condition is true than code inside the loop is execute either loop is terminated.

Then, we set the if statement and pass the condition, if the condition is true the output would be print either if the condition is false the if statement is terminated.

User Naveen R Kumar
by
5.6k points