Question

to find the greatest and smallest among 4 numbers. Use else if. Sample Output: Enter four numbers: 2 10 -9 Greatest is 10 and

Language C

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

The code for above program is given below, i have commented in line for explanation.

Code:-

#include <stdio.h>

int main()
{
int a,b,c,d;
printf("Enter four numbers: ");
scanf("%d%d%d%d",&a,&b,&c,&d);
  
// variable to store maximum value
int max;
  
// compare a with b,c,d
if((a>b) && (a>c) && (a>d))
// store a in max
max = a;

// compare b with a,c,d
if((b>a) && (b>c) && (b>d))
// store b in max
max = b;

// compare c with b,a,d
if((c>a) && (c>b) && (c>d))
// store c in max
max = c;

// compare d with b,c,a
if((d>a) && (d>b) && (d>c))
// store d in max
max = d;

// variable to store minimum value
int min;
  
// compare a with b,c,d
if((a<b) && (a<c) && (a<d))
// store a in min
min = a;
  
// compare b with a,c,d
if((b<a) && (b<c) && (b<d))
// store b in min
min = b;
  
// compare c with b,a,d
if((c<a) && (c<b) && (c<d))
// store c in min
min = c;
  
// compare d with b,c,a
if((d<a) && (d<b) && (d<c))
// store d in min
min = d;
  
printf("Greatest is %d and smallest is %d",max,min);
return 0;
}

Output:-

Enter four numbers: 2 10 -97 Greatest is 10 and smallest is -9 ... Program finished with exit code 0 Press ENTER to exit cons

Hope it clears your doubt, in case of any doubt do comment.

Please up vote if it helps you :)

Add a comment
Know the answer?
Add Answer to:
Language C to find the greatest and smallest among 4 numbers. Use else if. Sample Output:...
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
  •    use C++ language Output the prime numbers between 1 and 1000 Ask the user for...

       use C++ language Output the prime numbers between 1 and 1000 Ask the user for a color. If they choose "red", use a while loop to output "red" 5 times. If they choose "green", output "green" seven times with a for loop. If they choose anything else, tell them to choose a better color. Create a random number between 1 and 6

  • use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers...

    use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers Write a program that generates n random numbers as follows: Asks the user to input a positive integer n Asks the user to input the maximum value (say m) for the integers to be generated. Write a program that generates the n numbers in the range 0 to m. The program stores the generated numbers in an array A[ Asks the user to enter...

  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the smallest integer among them and print it on the screen. Typical output screen should be as following: Write a complete C++ program to ask the user to enter 4 integers. The program must use a functionto find the smallest integer among them and print it on the screen. Typical output screen should be as following: Note: the code...

  • Use c language Project Euler #5: Smallest multiple H HackerRank This problem is a programming version...

    Use c language Project Euler #5: Smallest multiple H HackerRank This problem is a programming version ofProblem 5 from projecteuler.net 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from 1 to N? Input Format First line contains T that denotes the number of test cases. This is followed by...

  • C Programming Language The code below matches the sample input/output but is marked wrong. Are there...

    C Programming Language The code below matches the sample input/output but is marked wrong. Are there other ways to do this problem? The focus is on recursion and functions. #include<stdio.h> int joCheck(unsigned long long int number) { if(number % 7 == 0 || number % 8 == 0) { return 1; } else return 0; } int main() { int cases = 0; scanf("%d", &cases); for(int i = 1; i<=cases; i++) { unsigned long long int number; scanf("%d", &number); if(joCheck(number)...

  • In the Java language APCS Sorting Numbers Lab Write a program that reads in 3 floating-point...

    In the Java language APCS Sorting Numbers Lab Write a program that reads in 3 floating-point numbers (decimal numbers) and prints the three numbers in sorted order from smallest to largest. In your main method, create a scanner and get the 3 numbers from the user. Create a separate method called sort that accepts the 3 numbers prints them in the appropriate order. Sample Run#1 Please enter first number: 4 Please enter second number: 9 Please enter third number: 2.5...

  • . Write an 8086 assembly language program to find the prime numbers among 100 bytes of...

    . Write an 8086 assembly language program to find the prime numbers among 100 bytes of data in an array stored from the address 4000H: 1000H in the data segment and store the result from the address 4000H: 3000H. write the code using 8086 assembly language only i do not want any other language If you Do not sure please do not solve it

  • (Find the smallest element) use pointers to write a function that finds the smallest element in...

    (Find the smallest element) use pointers to write a function that finds the smallest element in an array of integers. Use {1,2,4,5,10,100,2,-22} to test the function. using the following header. int minindex(double* list, int size) example output: array size: 8 number 1: 1 number 2: 2 number 3: 4 number 4: 5 number 5: 10 number 6: 100 number 7: 2 number 8: -22 smallest element is: -22 C++ only.

  • Write an 8086 assembly language program to find the prime numbers among 100 bytes of data...

    Write an 8086 assembly language program to find the prime numbers among 100 bytes of data in an array stored from the address 4000H: 1000H in the data segment and store the result from the address 4000H: 3000H.

  • Topics If/Else statement Description    Write a program that determines the larger of the two numbers...

    Topics If/Else statement Description    Write a program that determines the larger of the two numbers provided by the user. The program asks the user to enter a number. Then it asks the user to enter another but a different number. Then, it determines the larger of the two numbers and displays it to the user. (If the user happens to enter the two numbers the same, the program may report either of the two numbers as larger.) Requirements Do...

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