Q-16. (middle_num) Write a program to take three numbers and find the middle number among them.

0

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5.     float num1,num2,num3;//declare variables
  6.     printf("Enter three numbers to find middle\n");
  7.     scanf("%f %f %f",&num1,&num2,&num3);
  8. //takes input from user
  9.     if(num1>num2){
  10.         if(num2>num3){
  11.         printf("%.2f is a middle number",num2);
  12.     }
  13.     else if(num3>num1){
  14.         printf("%.2f is a middle number",num1);
  15.     }
  16.     else{
  17.         printf("%.2f is a middle number",num3);
  18.     }
  19.     }
  20.     else{
  21.         if(num2<num3){
  22.         printf("%.2f is a middle number",num2);
  23.     }
  24.     else if(num3<num1){
  25.         printf("%.2f is a middle number",num1);
  26.     }
  27.     else{
  28.         printf("%.2f is a middle number",num3);
  29.     }
  30.     }
  31.     getch();
  32.     return 0;
  33. }







Post a Comment

0Comments
Post a Comment (0)