Tuesday, 21 June 2016

Program in C language To check whether a no. is Armstrong or not

Following is the program to check whether a number is Armstrong or not :-





#include <stdio.h>
#include<conio.h>

int main()
{
    int number, originalNumber, remainder, result = 0;  
    printf("Enter a three digit integer: ");
    scanf("%d", &number);
    originalNumber = number;
    while (originalNumber != 0)
       {
            remainder = originalNumber%10;
             result += remainder*remainder*remainder;   //to reverse the given input
              originalNumber /= 10;
       }
            if(result == number)                                    //to check whether Armstrong no. condition is met
            printf("%d is an Armstrong number.",number);
    else
            printf("%d is not an Armstrong number.",number);

    return 0;
}

Output :-






Note- using the same logic we can design this program in C++ too

No comments:

Post a Comment