Problem 10

author
By Supreme2023-02-23
Problem Statement :
Write a program to read three numbers from keyboard and find out maximum out of these three. (nested if else)
Code:

#include <stdio.h>

int main()
{

// 10. Write a program to read three numbers from keyboard and find out maximum out of these
// three. (nested if else)

printf("\tFind Maximum Value");
printf("\n==============================");

float a, b, c;

printf("\n\nEnter The Value Of A : ");
scanf("%f", &a);

printf("\nEnter The Value Of B : ");
scanf("%f", &b);

printf("\nEnter The Value Of C : ");
scanf("%f", &c);

printf("\n_______________________________\n\n");

if (a > b)
{
if(a > c){
printf("A Has Maximum Value");
}
else
{
printf("C Has Maximum Value");
}
}

else if (b > a)
{
if(b > c){
printf("B Has Maximum Value");
}
else
{
printf("C Has Maximum Value");
}
}

printf("\n_______________________________\n\n");

return 0;
}

Description :
  • This C program reads three numbers from the user and finds the maximum value among them using nested if-else statements.
  • The program first prompts the user to enter three numbers using printf statements. It then takes the user inputs using the scanf function.
  • Next, the program checks the values of the input numbers using nested if-else statements. If a is greater than b, it checks if a is greater than c. If it is, it prints "A Has Maximum Value". Otherwise, it prints "C Has Maximum Value". Similarly, if b is greater than a, it checks if b is greater than c. If it is, it prints "B Has Maximum Value". Otherwise, it prints "C Has Maximum Value".
  • Finally, the program prints some more messages and returns 0 to indicate successful completion of the program.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.