Question

In: Computer Science

write a program that gets four digits from the user and tests to see which digit...

write a program that gets four digits from the user and tests to see which digit is the biggest and which is the smallest, use single-alternative only

sample output is below:

enter four digits and i will tell you which is biggest and smallest:
4 6 7 9

the biggest is 9

the smallest is 4

Solutions

Expert Solution

PROGRAM IS DONE WITH C++ LANGUAGE.

IT IS TESTED IN DEV-C++ 5.11 SOFTWARE AND IS GIVING CORRECT OUTPUT.

PROGRAM IS DONE IN TWO WAYS

PROGRAM 1. TAKE INDIVIDUAL 4 DIGITS FROM USER AND FIND MAX AND MIN FROM THEM.

PROGRAM 2. TAKE 4 DIGITS IN NUMBER FORMAT, FROM USER THEN FIND THE MAX AND MIN DIGITS FROM THEM.

PROGRAM 1

#include<iostream>
using namespace std;
int main()
{
   int dig[4],i;
   int max=0,min;
   /* enter 4 digits */
   cout<<"enter four digits" <<endl;
   for(i=0;i<4;i++)
   {
       cin>>dig[i];
   }
   /* calculate max value */
   for(i=0;i<4;i++)
   {
       if(dig[i]>max)
       {
           max=dig[i];
       }
   }
   min=dig[0];
   /* calculate min value */
   for(i=0;i<4;i++)
   {
       if(min>dig[i])
       {
           min=dig[i];
       }
   }
   /* print max and min value */
   cout<<endl<<"the biggest is " <<max;
   cout<<endl<<"the smallest is "<<min;
   return 0;
}

SCREEN SHOT

OUTPUT

PROGRAM 2

#include<iostream>
using namespace std;
int main()
{
   int dig[4],i,n;
   int max=0,min;
   i=0;
   /* enter 4 digit number */
   cout<<"enter a number of 4 digits :";
   cin>>n;
   /* while loop will run until n is zero */
   while(n!=0)
   {
       /* take digits in array */
       dig[i]= n%10;
       n=n/10;
       i++;
   }
   /* calculate max value */
   for(i=0;i<4;i++)
   {
       if(dig[i]>max)
       {
           max=dig[i];
       }
   }
   min=dig[0];
   /* calculate min value */
   for(i=0;i<4;i++)
   {
       if(min>dig[i])
       {
           min=dig[i];
       }
   }
   /* print max and min value */
   cout<<endl<<"the biggest is " <<max;
   cout<<endl<<"the smallest is "<<min;
   return 0;
}

SCREEN SHOT

OUTPUT


Related Solutions

Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user...
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user on one line (digits are separated by white space) and adds them to a list. The first digit and the last digit should not be a zero. If the user provides an invalid entry, the program should prompt for a new value. Converts every entry in the list to an integer and prints the list. The digits in the list represent a non-negative integer....
From the digits 0,1,2,3,5,7,8, and 9 , selected of them at random and from a four-digit...
From the digits 0,1,2,3,5,7,8, and 9 , selected of them at random and from a four-digit number, none of these digits appears more than once in each number. (a) Find the probability that the number formed is even. (b) Find the probability that the number formed is divisible by 3.
You will write a program that prompts the user to enter a 7-digit phone numbers, and...
You will write a program that prompts the user to enter a 7-digit phone numbers, and finds the 3- and 4-letter words that map to the phone number, according to the restrictions outlined earlier. A sample run: unixlab% java MapNumbers Enter name of dictionary file: words10683 Enter a test word (3 letters): cat Test word maps to 228 Enter telephone number (7 digits, no 0's or 1's, negative to quit): 2282273 Options for first 3 digits: act cat bat Options...
Write a program that does the following: Prompts the user for a 5-digit number. Divides that...
Write a program that does the following: Prompts the user for a 5-digit number. Divides that number into its separate five digits. Adds up the sum of those five digits. Outputs that sum You should test your program with at least the following test cases. (I am to be programming with python) >>> RESTART: /Users/mamp/Desktop/Desktop - Enter a 5-digit number: 12345 15 >>> RESTART: /Users/mamp/Desktop/Desktop - Enter a 5-digit number: 00000 0 >>> RESTART: /Users/mamp/Desktop/Desktop - Enter a 5-digit number:...
Write a C++ program that asks the user to enter a series of single-digit numbers with...
Write a C++ program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. It is...
Write a function called main which gets a single number, furlongs, from the user and converts...
Write a function called main which gets a single number, furlongs, from the user and converts that to meters and prints out the converted result. The math you need to know is that there are 201.16800 meters in a furlong. your results should yield something like these test cases. >>> main() How many furlongs? 10 your 10 furlongs are 2011.68 Meters >>> main() How many furlongs? 24 your 24 furlongs are 4828.032 Meters
In a four-digit lottery, each of the four digits is supposed to have the same probability...
In a four-digit lottery, each of the four digits is supposed to have the same probability of occurrence. The table shows the frequency of occurrence of each digit for 87 consecutive daily four-digit drawings. Digit Frequency 0 37 1 40 2 31 3 43 4 34 5 31 6 37 7 29 8 30 9 36 Total 348 (b) Calculate the chi-square test statistic, degrees of freedom, and the p-value. (Round your test statistic value to 2 decimal places and...
In a four-digit lottery, each of the four digits is supposed to have the same probability...
In a four-digit lottery, each of the four digits is supposed to have the same probability of occurrence. The table shows the frequency of occurrence of each digit for 83 consecutive daily four-digit drawings. Digit Frequency 0 26 1 32 2 27 3 40 4 31 5 31 6 33 7 44 8 33 9 35 Total 332 Click here for the Excel Data File (a) The hypothesis for the given issue is H0: The digits come from a uniform...
Question: How many even four-digit numbers can be formed from the digits 0,1,2,5,6 and 9. If...
Question: How many even four-digit numbers can be formed from the digits 0,1,2,5,6 and 9. If each digit can be used exactly once. Note: Using the rule of multiplication, solve the question elaborating and explaining each step in detail for my better understanding.
Write a program which prompts the user for the year of their birth, and which then...
Write a program which prompts the user for the year of their birth, and which then calculates their age (ignoring the month/day). Split the program into `main`, a "prompt for year" function which tests to make sure the user's input is a valid year, and a "calculate age" function which performs the actual calculation. (You can assume the current year is 2017.) for my intro to c++ class
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT