Header Ads Widget

Ticker

6/recent/ticker-posts

C PROGRAM TO CHECK ARMSTRONG NUMBER (ALGORITHM AND FLOWCHART)

 COMPUTER GAYN


Q.   Write the C program and algorithm to check the armstrong                     number also draw flowchart?
ans:-
             #include <stdio.h>
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


  1.         step1:- Input the number.
  2.         step2:- Initialize sum=0 and temp=number.
  3.         step3:- Find the total number of digits in the number.
  4.         step4:- Repeat until (temp != 0)
  5.         step5:- remainder = temp % 10
  6.         step6:-result = resut + pow(remainder,n)
  7.         step7:- temp = temp/10
  8.         step8:- if (result == number)
  9.                     Display "Armstrong"
  10.         step9:- Else
  11.                     Display "Not Armstrong"



FLOWCHART


























      

Post a Comment

0 Comments