C Program to print all Armstrong numbers Between n and m using While loop

C Program to print all Armstrong numbers Between n and m using While loop

Write C Program to print all Armstrong numbers Between n and m using While loop

//Write a C program to print Armstrong number between n and m using while loop

#include <stdio.h>
#include <stdbool.h>
bool isArmstrong(int n)
{
	int temp = n, ans = 0;
	while(n != 0)
	{
		int remainder = n % 10;
		ans = ans + (remainder * remainder * remainder);
		n = n / 10;
	}
	if(temp != ans)
	{
		return false;
	}
	return true;
}

int main()
{
	int n,m;
	printf("Enter n :--> ");
	scanf("%d", &n);

	printf("Enter m :--> ");
	scanf("%d", &m);

	printf("Armstrong numbers between %d to %d :--> ", n, m);
	int i = n ,j = m;
	while(i < j)
	{
		if(isArmstrong(i))
		{
			printf("%d ",i);
		}
		i++;
	}

	return 0;
}

Output:

Enter n :--> 300
Enter m :--> 400

Armstrong numbers between 300 to 400 :--> 370 371