C program to check whether a certain number is Armstrong or not - wordsclank.in

Thursday, 8 March 2018

C program to check whether a certain number is Armstrong or not

A  number of n digit is called Armstrong number if sum of the power of n of its digits is equal to the number itself.
For example a number of three digits integer is an Armstrong number if the sum of the cubes of its digits is equal to the number itself. 153 is an Armstrong number since 1**3 + 5**3 + 3**3 = 371. 
armstrong number in C,armstrong number


Most Related:






SOURCE CODE



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#include
#include


int main()

{

    int num, rem, altnum, result = 0, n = 0 ;


    printf("Enter an integer: ");

    scanf("%d", &num);


     altnum = num;

    

    while (altnum != 0)

    {

        altnum /= 10;

        n++;

    }


    altnum = num;


    while (altnum != 0)

    {

        rem = altnum % 10;

        result = result + pow(rem, n);

        altnum /= 10;

    }


    if(result == num)

        printf("%d is an Armstrong number.", num);

    else

        printf("%d is not an Armstrong number.", num);


    return 0;

}



OUTPUT

armstrong number,armstrong number in C


No comments:

Post a Comment