Answer to Question #118042 in C for BIBEK KUMAR

Question #118042
PROGRAM TO VERIFY ARMSTRONG NUMBER....FILL THE BLANKS.

#include <stdio.h>
void main() {
int number, temp, remainder, i, power, digits = 0, sum = 0;
printf("Enter a number : ");
scanf("%d", &number);
temp = number;
while (..................) { // complete the condition to iterate the Loop
digits=............; // increment the digits
temp=..............; //calculate the temp value

temp = number;
while (...............) { // complete the condition to iterate the Loop
remainder = number % 10;
i = 1;
power = 1;
while (................) // find the powers of each digit
power=..........................;// calculate power value
i.............; // increment i value
}
sum =..............; // calculate sum value
number=..................; // calculate number value

if (................) {
printf("The given number %d is an armstrong number\n", temp);
}else {
printf("The given number %d is not an armstrong number\n", temp);}
}
}
1
Expert's answer
2020-05-25T18:51:20-0400
#include <stdio.h>
#include <math.h>


int main() {
    int number, temp, remainder, i, power, digits = 0, sum = 0;


    printf("Enter a number : ");


    scanf("%d", &number);


    temp = number;


    while (temp != 0) {    // complete the condition to iterate the Loop


        digits = digits + 1;    // increment the digits


        temp = temp / 10;    //calculate the temp value
    }
    temp = number;


    while (temp > 0) {    // complete the condition to iterate the Loop


        remainder = temp % 10;


        sum = sum + pow(remainder, digits);
        temp = temp / 10;


    }


    if (number == sum) {


        printf("The given number %d is an armstrong number\n", number);


    } else {


        printf("The given number %d is not an armstrong number\n", number);
    }


    return 0;


}



Output:


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS