codescracker


c

C Program to Check Number is Armstrong or Not



« Previous Program Next Program »


Check Armstrong or Not

To check whether the input number is Armstrong number or not Armstrong number in C programming, first, you have to ask to the user to enter the number. Now, to check whether any positive number is an Armstrong number or not, following is the example :

C Programming Code to Check Number is Armstrong or Not

Following C program ask to the user to enter any positive integer to find whether it is Armstrong number or not, then display the result on the screen:

/* C Program - Check Armstrong or Not */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int n, nu, num=0, rem;
	printf("Enter any positive number : ");
	scanf("%d",&n);
	nu=n;
	while(nu!=0)
	{
		rem=nu%10;
		num=num + rem*rem*rem;
		nu=nu/10;
	}
	if(num==n)
	{
		printf("Armstrong Number");
	}
	else
	{
		printf("Not Armstrong Number");
	}
	getch();
}

When the above c program is compile and executed, it will produce the following result:

Above C Programming Example Output (for Armstrong number):
c program to check number is armstrong or not

Above C Programming Example Output (for not Armstrong number):
c program check armstrong or not

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test