Write a MAX function that determines the maximum of two real numbers.

Write a program using the MAX function to determine the maximum of four real numbers entered on the keyboard.


Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>

double MAX(double X, double Y)
{
	return (X>Y) ? X : Y;
}

void main()
{
	double A, B, C, D;

	printf("Enter 4 doubles : ");
	scanf("%lf %lf %lf %lf", &A, &B, &C, &D);
	printf("The maximum is equal to %f \n",
		MAX(MAX(A, B), MAX(C, D)));

	getch();
}

 

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Program output 12