Subscribe for more such posts..

Dear Reader...
I hope u are like my posts. If so then please don't forget to like , share and follow my blog for more such posts ,also feel free to write suggestions in the comment box given over here.

Thank you...

Search This Blog

Program to print out all the Armstrong number between given intervals in C.


#include <stdio.h>
#include <math.h>
int main()
{
	int low , high , num , onum , rem , count = 0;
	int result = 0 ;
	printf("Enter the values of n1 and n2 separated by space : ");
	scanf("%d %d" , &low , &high);
	
	printf("Armstrong numbers between %d an %d are : " , low , high);
	 
	for (num = low  ; num <= high ; ++num )
	{
		
		
		onum = num ;
		
		while (onum != 0) 
		{
			onum = onum / 10 ;
			++count ;
		}
		
		onum = num ;
		
		while (onum != 0)
		{
			rem = onum % 10 ;
			result += pow(rem , count);
			onum /= 10 ;
		
		}
		
		if (result == num)
		{   
		    
			printf("%d " , num);
		  
			
		}
		
	
		count = 0 ;
		result = 0 ;
		

	
	}
	
     printf("\n");
	return 0 ;
	

	
	
}


No comments:

Post a Comment