C program to check whether a number entered by user is Armstrong or not

/* C program to check whether a number entered by user is Armstrong or not. */
 
#include <stdio.h>
int main()
{
	int n, n1, rem, num = 0;
	printf("Enter a positive  integer: ");
	scanf("%d", &n);
	n1 = n;
	while (n1 != 0)
	{
		rem = n1 % 10;
		num += rem*rem*rem;
		n1 /= 10;
	}
	if (num == n)
		printf("%d is an Armstrong number.", n);
	else
		printf("%d is not an Armstrong number.", n);
}

Capture.PNG
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s