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....
Playing with encryption: Write a program that will read a four-digit integer entered by the user...
Playing with encryption: Write a program that will read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the second digit with the fourth. Finally, print the original number and its encrypted one. Now reverse the process. Read an encrypted integer and decrypt it by reversing the algorithm to obtain the original...
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.
in .java Write a program that reads an integer with 3 digits and prints each digit...
in .java Write a program that reads an integer with 3 digits and prints each digit per line in reverse order. Hint: consider what you get from these operations: 319%10, 319/10, 31%10, ... Enter an integer of exactly 3 digits(e.g. 538): 319 9 1 3 Hint: consider what you get from these operations: 319%10 319/10 31%10
C programming Get a number from the user and write a program that checks to see...
C programming Get a number from the user and write a program that checks to see if the inputted number is equal to x*x+x and x must be greater than 0. For example, if the user inputs 12. The program should check to see if 12 = x*x+x. In this case it is true because 3*3+3 = 12.
Solve following tasks using MIPS Task Write a program that gets a number from user and...
Solve following tasks using MIPS Task Write a program that gets a number from user and displays “Even”, or “Odd. (If-else) Write a program that input a number from user displays each digit separately. For example if input is 3986, output is  6, 8, 9 ,3. (Loop) Write a program that converts a decimal number to binary. (Loop) Hint for Task 1 and Task 3.     Use, div $tdivident,$tdivider and mfhi $tdestination instructions. For example, Div $t1,$t2 will divide $t1...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT