Largest number in C
Q. Write a C program to find the largest number among three number using simple if statement ?
#include <stdio.h>
#include <conio.h>
void main()
{
int n1, n2, n3;
clrscr();
printf("Enter the three different numbers: ");
scanf("%d %d %d", &n1, &n2, &n3);
if( n1>n2 && n1>n3 )
{
printf("%d is the largest number.", n1);
}
if( n2>n1 && n2>n3 )
{
printf("%d is the largest number.", n2);
}
if( n3>n1 && n3>n2 )
{
printf("%d is the largest number.", n3);
}
getch();
}
Q. Write an algorithm to find the largest number among three number using simple if statement ?
1. Start
2. Read the values of `n1`, `n2`, and `n3` from the user.
3. If `n1 > n2` and `n1 > n3`, then
- `n1` is the largest number.
- Print "`n1` is the largest number."
4. Else if `n2 > n1` and `n2 > n3`, then
- `n2` is the largest number.
- Print "`n2` is the largest number."
5. Else
- `n3` is the largest number.
- Print "`n3` is the largest number."
6. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com