Computer Science, asked by vcphitesh, 3 months ago

Input a list of numbers and test if a number is equal to the sum of the cubes of its
digits. Find the smallest and largest such number from the given list of numbers.

Answers

Answered by dreamrob
0

Program in C++

#include<iostream>

#include<string.h>

using namespace std;

int main()

{

int n , count = 0;

cout<<"Enter the number of elements : ";

cin>>n;

int A[n] , B[n];

cout<<"Enter the elements in the list : "<<endl;

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

{

 cin>>A[i];

}

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

{

 int t = A[i];

 int s = 0;

 while(t != 0)

 {

  int d = t % 10;

  s = s + (d * d * d);

  t = t / 10;

 }

 if(A[i] == s)

 {

  B[count] = A[i];

  count++;

 }

}

if(count == 0)

{

 cout<<"There are no such numbers in the list";

}

else

{

 int min = B[0] , max = B[0];

 cout<<"Such numbers are : "<<endl;

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

 {

  cout<<B[i]<<endl;

  if(B[i] > max)

  {

   max = B[i];

  }

  if(B[i] < min)

  {

   min = B[i];

  }

 }

 cout<<"Smallest number : "<<min<<endl;

 cout<<"Largest number : "<<max;

}

return 0;

}

Similar questions