Computer Science, asked by Meghana7610, 11 months ago

Write a c program to input n elements in array and display all the armstrong numbers.

Answers

Answered by sswaraj04
1

Answer:

#include <stdio.h>

#include <math.h>

int main()

{

   int n;

   printf("Enter no. of inputs to be made: ");

   scanf("%d", &n);

   int arr[n];

   printf("Enter %d numbers now",n);

   for(int i=0;i<n;i++)

   {

   scanf("%d", &arr[i]);

   }

   printf("Armstrong numbers are :\n");

   for(int i=0;i<n;i++)

   {

   int num, rem, result = 0, n = 0 ;

    num = arr[i];

   

   while (num != 0)

   {

       num /= 10;

       ++n;

   }

   num = arr[i];

   while (num != 0)

   {

       rem = num%10;

       result += pow(rem, n);

       num /= 10;

   }

   if(result == arr[i])

       printf("%d \n", arr[i]);

   }

   return 0;

}

Explanation:

Hope it helps :-)

Similar questions