Sun May 20 2018

Armstrong Number

C Programming1006 views

File Name: armstrong-number.c

#include<stdio.h>

int main() {
	int no, i, mod, ans;
	printf("Check the given number is armstrong or not\n");
	printf("Enter a number:\n");
	scanf("%d", &no);
	i = no;

	/* Loop the process using "while loop" */
	while(i != 0) {
		mod = i % 10;
		ans += (mod * mod * mod);
		i = i / 10;
	}
	if(ans == no)
		printf("It's a Armstrong Number!\n");
	else
		printf("It's not a Armstrong Number!\n");
	return 0;
}



/* Output */
Check the given number is armstrong or not
Enter a number:
153

It's a Armstrong Number!

/* ---------------------------------------- */

Check the given number is armstrong or not
Enter a number:
168

It's not a Armstrong Number!
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.