Question

C++ You are to accept 3 letters from the user. Print the letter in order from...

C++

You are to accept 3 letters from the user.

Print the letter in order from smallest to largest, then print the letter from largest to smallest.

Next accept 3 numbers from the user

Print the largest number

Print the smallest number

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int Minimum(int i, int j, int k){
   if(i<j && i<k){
      return i;
   }
   else if(j<k){
      return j;
   }
   else{
      return k;
   }
}

int Maximum(int i, int j, int k){
   if(i>j && i>k){
      return i;
   }
   else if(j>k){
      return j;
   }
   else{
      return k;
   }
}


int main()
{
   char arr[3], temp;
   int n = 3, i, j, k;
   cout<<"Enter letter1: ";
   cin>>arr[0];
   cout<<"Enter letter2: ";
   cin>>arr[1];
   cout<<"Enter letter3: ";
   cin>>arr[2];

   for (i = 0; i < n - 1; i++) {
        for (j = 0; j < n - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
    
    cout<<"Letters from small to large: ";
    for(i = 0;i<n;i++){
       cout<<arr[i]<<" ";
   }
   cout<<endl;
   
   cout<<"Letters from large to small: ";
    for(i = n-1;i>=0;i--){
       cout<<arr[i]<<" ";
   }
   cout<<endl;
   cout<<endl;
   
   
   cout<<"Enter number1: ";
   cin>>i;
   
   cout<<"Enter number2: ";
   cin>>j;
   
   cout<<"Enter number3: ";
   cin>>k;
   
   cout<<"Small number = "<<Minimum(i,j,k)<<endl;
   cout<<"Large number = "<<Maximum(i,j,k)<<endl;
   
   return 0;
}

nter letter1: d Enter letter2: a Enter letter3 s Letters from small to large: a d s Letters from large to small: s d a Enter number1:4 nter number 2: 1 nter number 3: 2 Small number1 Large number4 Process exited after 7.103 seconds with return value0 Press any key to continue . -

\color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
C++ You are to accept 3 letters from the user. Print the letter in order from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT