write a program that determines whether a given positive integer is an armstrong number.

-----armstrong number is an n-digit number that is equal to the sum of the nTH power of each digit.

your program should contain the following:

A. funtion that returns a value when x is raised to y.
B. funtions that determines the number of digits in an n-digit number.

use these funtions to determine if a number is an armstrong number.

thankyou. much appreciated.

The standard library function pow(x, y) returns the result when x is raised to y.

The following function returns the number of digits in a number n.

``````int getNOOfDigits(int n)
{
int count = 0;

while(n > 0)
{
count++;
n /= 10; //Divide an integer by 10 and see what happens.
}
return count;
}``````

Using these functions it becomes very easy to check if a number is Armstrong.

Note that you can obtain the last digit of a number by:

``r = n % 10; //here r is the last digit of n.``

Now you can work the rest out yourself!!!
Believe me, Its real easy. Anyone can work it out!!!

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

int main()
{
int n,i,rev=0,num;
printf("\n Enter a number : ");
scanf("%d",&n);
num=n;
while(n) {
rev=rev*10+n%10;
n/=10;
}
if(num==rev)
printf("\n Is Armstrong");
else
printf("\n Not an Armstrong");
}``````
``````#include<stdio.h>
#include<conio.h>

int main()
{
int n,i,rev=0,num;
printf("\n Enter a number : ");
scanf("%d",&n);
num=n;
while(n) {
rev=rev*10+n%10;
n/=10;
}
if(num==rev)
printf("\n Is Armstrong");
else
printf("\n Not an Armstrong");
}``````

This program does not tell whether a number is armstrong or not. This is a program to test whether a number is equal to its reverse...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.