COMPUTER GAYN
Q. Write the C program and algorithm to check the armstrong number also draw flowchart?
ans:-
#
int main() {
int num, originalNum, remainder, result = 0;
printf("Enter a three-digit integer: ");
scanf("%d", &num);
originalNum = num;
while (originalNum != 0) {
// remainder contains the last digit
remainder = originalNum % 10;
result += remainder * remainder * remainder;
// removing last digit from the orignal number
originalNum /= 10;
}
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return 0;
}ALGORITHM
- step1:- Input the number.
- step2:- Initialize sum=0 and temp=number.
- step3:- Find the total number of digits in the number.
- step4:- Repeat until (temp != 0)
- step5:- remainder = temp % 10
- step6:-result = resut + pow(remainder,n)
- step7:- temp = temp/10
- step8:- if (result == number)
- Display "Armstrong"
- step9:- Else
- Display "Not Armstrong"
FLOWCHART
0 Comments