Follow This Blog For more... 😊

Program to take a number from user and check whether it is Armstrong number or not.| Using C language| C Program series 20|

👨‍💻Program to accept a number and check whether it is an Armstrong number or not.

Code:


    //Program to take a number from the user and check whether it is an Armstrong number or not.
    #include<stdio.h>
    main()
    {
        printf("Program to take a number from user and check whether it is Armstrong number or not.\n\n");
       
        int n,r,temp,sum=0;
        /*Where,
        n = number
        r = remainder
        temp = temporary
        sum = sum
        */
       
        printf("Enter the number:");
        scanf("%d",&n);
       
        temp=n;
       
        while(n>0)
        {
            r=n%10;
            sum=sum+(r*r*r);
            n=n/10;
        }
       
        if(sum==temp)
        {
            printf("%d is a Armstrong number.",temp);
        }
        else
        {
            printf("%d is not a Armstrong number.",temp);
        }
    }

Output: 







👉Click for more C Program series Questions.

Comments

Popular Posts