Write a program to print the largest of three numbers?
Answers
Answer:
// Print largest of 3 no.s
import java.util.*;
class Print
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int a,b,c;
System.out.print("Enter 3 no.s\n");
if(a>b)
{
if (a>c)
System.out.println(a+"is the largest");
else if(c>a)
System.out.println(c+"is the largest");
}
if(b>a)
{
if (b>c)
System.out.println(b+"is the largest");
else if(c>b)
System.out.println(c+"is the largest");
}
if(c>b)
{
if (a>c)
System.out.println(a+"is the largest");
else if(c>a)
System.out.println(c+"is the largest");
}
}
}
Hope this helps you.
Answer:
Explanation:
#include <stdio.h>
int main()
{
double n1, n2, n3;
printf("Enter three different numbers: ");
scanf("%lf %lf %lf", &n1, &n2, &n3);
if( n1>=n2 && n1>=n3 )
printf("%.2f is the largest number.", n1);
if( n2>=n1 && n2>=n3 )
printf("%.2f is the largest number.", n2);
if( n3>=n1 && n3>=n2 )
printf("%.2f is the largest number.", n3);
return 0;
}