A Program to Find the Largest Number

In this example, we are giving a program to find the largest number among the given three numbers.


Program to find the largest number among the given three numbers:

  1. #include <stdio.h>
  2. int main()
  3. {
  4. double n1, n2, n3;
  5. printf("Enter three numbers: ");
  6. scanf("%lf %lf %lf", &n1, &n2, &n3);
  7. if( n1>=n2 && n1>=n3 )
  8. printf("%.2f is the largest number.", n1);
  9. if( n2>=n1 && n2>=n3 )
  10. printf("%.2f is the largest number.", n2);
  11. if( n3>=n1 && n3>=n2 )
  12. printf("%.2f is the largest number.", n3);
  13. return 0;
  14. }

Output:

Enter three numbers: 17.3
-25.9
14.7
17.3 is the largest number.