Find Is It Armstrong Number or Not

code by me:

#include<stdio.h>
#include<math.h>
int getTotalDigits(int);
int isArmStrong(int,int);

int getTotalDigits(int n)
{
    int count=0;
    while(n>0)
    {
        n=n/10;
        count++;
    }
    return count;
}

int isArmStrong(int count, int n)
{
    int temp=n;
    int sum=0;

    while(n>0)
    {
        sum=sum+pow(n%10,count);
        n=n/10;
    }
    if(temp==sum)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int main()
{
    int n;
    scanf("%d",&n);
    int count = getTotalDigits(n);

    int a=isArmStrong(count, n);
    if(a==1)
    {
        printf("%d is armstrong number\n",n);
    }
    else
    {
        printf("%d is not armstrong number\n",n);
    }
    return 0;
}

Logic and Code From the Vids:

#include<stdio.h>
#include<math.h>
int getTotalDigits(int);
int isArmStrong(int n);

int getTotalDigits(int n)
{
    int count = 0;
    while(n>0)
    {
        n=n/10;
        count++;
    }
    return count;
}

int isArmStrong(int n)
{
    int count=getTotalDigits(n);
    int temp=n;
    int sum=0;
    while(n>0)
    {
        sum=sum+pow(n%10,count);
        n=n/10;
    }
    return temp==sum;
}

int main()
{
    int i;
    for(i=1; i<=50000; i++)
    {
        if(isArmStrong(i))
        {
            printf("%d is armstrong number\n",i);
        }
    }

    return 0;
}

Vid:

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *