-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargestOf3.c
More file actions
48 lines (43 loc) · 1.79 KB
/
largestOf3.c
File metadata and controls
48 lines (43 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @file largestOf3.c
* 11.Write a program that accepts three integers and find the maximum of three.
* @author Md. Alamin (alamin5g@yahoo.com)
* I would love be a software engineer at Google. That is why anybody can uses this code without any condition, if you face any difficulty, then try to email me.
* @version 0.1
* @date 2022-03-13
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
void main(){
int n1, n2, n3, largest;
printf("Enter 3 separate integer for n1, n2 and n3 to find out the largest number: ");
scanf("%d %d %d", &n1, &n2, &n3);
largest = (n1>n2)?((n1>n3)?(n1):(n3)):((n2>n3)?(n2):(n3)); //ternary operator, see more on google
printf("%d is the largest number among n1 = %d, n2 =%d and n3=%d\n\n", largest, n1, n2, n3);
//or u can use if else to findout the largest number;
if(n1> n2){
if (n1>n3)
{
printf("%d is the largest number among n1 = %d, n2 =%d and n3=%d", n1, n1, n2, n3);
}else{
printf("%d is the largest number among n1 = %d, n2 =%d and n3=%d", n3, n1, n2, n3);
}
}else {
if (n2>n3)
{
printf("%d is the largest number among n1 = %d, n2 =%d and n3=%d", n2, n1, n2, n3);
}else{
printf("%d is the largest number among n1 = %d, n2 =%d and n3=%d", n3, n1, n2, n3);
}
}
///Or you can use this if else if else method to findout the largest number
if(n1>n2 && n1> n3){
printf("\n\n%d is the largest number among n1 = %d, n2 =%d and n3=%d", n1, n1, n2, n3);
} else if(n2> n1 && n2> n3){
printf("\n\n%d is the largest number among n1 = %d, n2 =%d and n3=%d", n1, n1, n2, n3);
} else{
printf("\n\n%d is the largest number among n1 = %d, n2 =%d and n3=%d", n3, n1, n2, n3);
}
}