35: W.A.P. to decide whether number is Armstrong or not .

 

35: W.A.P. to decide whether number is Armstrong or not . 

Please follow me for more practicals....


Program:

 

#include <stdio.h>

#include <conio.h>

 

void main()

{

    clrscr();

    int num, r, temp, sum = 0;

 

    printf("Enter the num = ");

    scanf("%d", &num);

 

    temp = num;

 

    while (num > 0)

    {

        r = num % 10;

        sum = sum + r * r * r;

        num = num / 10;

    }

 

    if (temp == sum)

        printf("\n%d is armstrong.", temp);

    else

        printf("\n%d is not armstrong.", temp);

 

    getch();

}

  

Please follow me for more practicals....


Output:

Enter the num = 153

 

153 is armstrong.

  

Please follow me for more practicals....


Algorithm:

        1.       START

        2.       Declare num, r, temp, sum = 0.

        3.       Enter the value of num.

        4.       temp = num.

        5.       Repeat upto step-8 until (num > 0).

        6.       r = num % 10.

        7.       sum = sum + (r * r * r).

        8.       num = num / 10.

        9.       If (temp == sum) then goto step-10 else goto step-11.

        10.   Display an armstrong, goto step-12.

        11.   Display not an armstrong.

        12.   STOP.

  

Please follow me for more practicals....


Flowchart:





 

Please follow me for more practicals....


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.