Computer Science, asked by bhanutej773, 4 months ago

write a program to create a single dimensional array of n integers .print only those integers from the array which are armstrong numbers

urgenttttt

Answers

Answered by rohitkhajuria90
5

Please refer the attached image

Attachments:
Answered by GulabLachman
3

The correct question is :

Write a c program to create a single dimensional array of n integers .print only those integers from the array which are Armstrong numbers.

Program:

#include<conio.h>

#include<stdio.h>

#define max 100

void Armstrong(int[],int);      

int main()

{

      int a[max], n, i=0;

      printf("Enter the limit of array: ");

      scanf("%d", &n);  

      printf("Enter the elements of array: ");

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

      {

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

       }

       Armstrong(a,n);

       getch();

return 0;

}  

void Armstrong(int a[max],int n)

{

       int i=0, temp, sum=0, rem, c=0;

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

       {

             sum=0;

             temp=a[i];

             while(a[i]!=0)

             {

                     rem=a[i]%10;

                     sum=sum+rem*rem*rem;

                     a[i]=a[i]/10;

              }

              if(temp == sum)

              {    

                      c++;

             }

       }  

       printf( " \nTotal Armstrong no is: %d ",c );

}    

Note:

A number is an Armstrong number if it is equal to the sum of its own digits raised to the power of the number of digits. example: 371 = 3³ + 7³ + 1³ = 27 + 343 + 1 = 371. so, 371 is an Armstrong number.  

Similar questions