AMCAT Automata Fix Sample Question-3

Program 3

CHECK LARGEST

The function/method largest check which number is largest out of three.
The function/method largest takes 3 integers as input and returns largest interger out of three integers.
The function/method largest compiles successfully but fails to get the desired result for some test cases due to logical errors. Your task is to fix the code so that it passes all the test cases.

void largest (int n1, int n2, int n3)
{

  if (n1 >= n2 && n1 <= n3)
	printf ("%d is the largest number.", n1);


  else if (n2 <= n1 && n2 >= n3)
	printf ("%d is the largest number.", n2);

  else
	printf ("%d is the largest number.", n3);

}
void largest (int n1, int n2, int n3)
{

  if (n1 >= n2 && n1 >= n3)
	printf ("%d is the largest number.", n1);


  else if (n2 >= n1 && n2 >= n3)
	printf ("%d is the largest number.", n2);


  else
	printf ("%d is the largest number.", n3);

}