Question

In: Computer Science

Write a C program that selects and displays the maximum value of five numbers to be...

Write a C program that selects and displays the maximum value of five numbers to be entered when the program is executed. (Hint : Use a for loop with both a scan_s and if statement inside the loop.)

Solutions

Expert Solution


#include<stdio.h>


int main()

{
  
   int i,MAX;
  
   int a[5];
  
  
  
   for(i=0;i<5;i++)
  
   {
      
       scanf("%d",a[i]);/* input 5 numbers */
  
   }  
  
   MAX=a[0];/*initialize the first number as maximum value*/
  
   for(i=0;i<5;i++)
  
   {
      
       if(a[i]>MAX)
      
       {
          
           MAX=a[i];
      
       }
  
   }
  
   printf("the maximum of 5 numbers is%d",MAX);

return 0;

}


Related Solutions

Write a C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by...
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by sum of the digits in them. For example, 2924 is divisible by (2+9+2+4 = 17). Your program should display all these possible numbers in the given range, and each number should be separated from the other by a space.
Write a C function that finds and displays the maximum value ina two-dimensional array of...
Write a C function that finds and displays the maximum value in a two-dimensional array of integers. The array should be declared as a 10-row-by-20-column array of integers in main (), and the starting the address of the array should be passed to the function. Modify the function so that it also displays the rows and columns number of the element with the maximum value
Write a program in C++ that generates and displays the first N three digit odd numbers....
Write a program in C++ that generates and displays the first N three digit odd numbers. Whereas the number N is provided by the user.
Please write program in C++ format: Write a program to accept five negative numbers from the...
Please write program in C++ format: Write a program to accept five negative numbers from the user. (1) Find the average of the five numbers and display the answer to the standard output. Keep the answer two decimal points - 5 points (2) Output the numbers in ascending order and display the answer to the standard output. - 5 points
Write a C++ program that displays the current time
Write a C++ program that displays the current time
In C, create a program that displays the minimum and maximum values stored in a data...
In C, create a program that displays the minimum and maximum values stored in a data file "datafile.txt". Use the following function prototype:  void minmaxarray(float value, float *min, float *max);
write a C program that asks the user to enter numbers and finds maximum among them
write a C program that asks the user to enter numbers and finds maximum among them
Must be done in C Write a C program found out the maximum value between the...
Must be done in C Write a C program found out the maximum value between the three numbers? Show steps with comments or else it will be flagged.
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a...
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an inpatient or an outpatient. If the patient was an inpatient, the following data should be entered: The number of days spent in the hospital The daily rate Hospital medication charges Charges for hospital services (lab tests, etc.) The program should ask for the following data if the patient was...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT