C Program to Print First n Armstrong Numbers using While loop

C Program to Print First n Armstrong Numbers using While loop

Write C Program to Print First n Armstrong Numbers using While loop

//Write a C program to print first n Armstrong number using while loop

#include <stdio.h>
#include <stdbool.h>
#include <math.h>

bool isArmstrong(int n)
{
	int temp = n,ans = 0, rem;
	int digits = ceil(log10(n));

	while(n != 0)
	{
		int remainder = n % 10;
		ans = ans + (remainder * remainder * remainder);
		n = n / 10;
	}
	if(temp == ans)
	{
		return true;
	}
	return false;
}

int main()
{
	int n;
	printf("Enter the number ( < 6) :--> ");
	scanf("%d", &n);

	long int i = 1 ;
	int count = 0;

	printf("First %d Armstrong Numbers Are :--> ", n);

	while(count < n)
	{
		if(isArmstrong(i))
		{
			printf("%ld ",i);
			count++;
		}
		i++;
	}

	return 0;
}

Output:

Enter the number ( < 6) :--> 5

First 5 Armstrong Numbers Are :--> 1 153 370 371 407