Computer Science, asked by aunsuac, 2 months ago

You are given a number. Find the largest three digit number contained within with the given number​

Answers

Answered by anvisha27008
0

Answer:

The descending order of the given numbers 7,6,3 is:

7>6>3  

We observe that the smallest digit is 3 and the largest digit is 7, so the number should start with 7 and end with 3.

 

Thus, the largest number formed is 763.

Hence, the greatest three digit number formed is 763.

Explanation:

Answered by pruthaasl
0

Answer:

#include <iostream>

using namespace std;

int main() {

   int n,i,j,t;

   int a[3];

   cout<<"\nEnter a three digit number: ";

   cin>>n;

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

   {

       while(n!=0)

       {

           a[i]=n%10;

           n/=10;

           break;

       }

   }

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

   {

       for(j=0;j<3;j++)

       {

           if(a[i]>a[j])

           {

               t=a[i];

               a[i]=a[j];

               a[j]=t;

           }

       }

   }

   cout<<"\nThe largest possible three digit number is ";

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

   cout<<a[i];

   return 0;

}

Explanation:

  • Declare the variables and array to store the data.
  • Take a three-digit number as input from the user and store it.
  • Separate each digit using the modulo operator and store them in an array.
  • Arrange the separated digits in descending order using the for and if loops.
  • Print the largest three-digit number contained within the given number.

#SPJ2

Similar questions