C Program to Generate First N Armstrong Numbers Where N is Given by User

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

int main()
{
	 int n, digitCount, number, sum, rem, i=2, count=1;
	 clrscr();
	 printf("Enter how many Armstrong numbers? \n");
	 scanf("%d", &n);
	
	 /* Generating Armstrong Numbers */
	 while(count <= n)
	 {
	
		  /* Finding number of digits */
		  number = i;
		  digitCount = 0;
		  while(number != 0)
		  {
			   digitCount++;
			   number = number/10;
		  }
		
		  /* Finding sum */
		  number = i;
		  sum = 0;
		  while(number != 0)
		  {
			   rem = number%10;
			   sum = sum + pow(rem, digitCount);
			   number = number/10;
		  }
		
		  /* Making Decision and Printing */
		  if(sum == i)
		  {
			   printf("%d\t", i);
			   count++;
		  }
		  i++;
	 }
	 getch();
	 return(0);
}

Output

Run 1:
----------
Enter how many Armstrong numbers?
5 ↲
1   2   3   4   5

Run 2:
----------
Enter how many Armstrong numbers?
15 ↲
1     2     3    4      5     6     7     8     9     153   
370   371   407  1634   8208

Leave a Reply

Your email address will not be published. Required fields are marked *

https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
About
Products
Subscribe

If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

    Applauz

    As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

    Subscribe

    If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

      Applauz

      As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

      Copyright by BOLD THEMES. All rights reserved.