+ 1

Program to find the largest number among 3 numbers using nested loop.

Using C,C++,JAVA

24th Sep 2021, 4:58 AM
Sugandha Das
5 Answers
+ 2
Please, show your attempt/code then explain the problem clearly. So, we can help. Thanks for understanding. Happy coding!
24th Sep 2021, 5:23 AM
mesarthim
mesarthim - avatar
+ 2
You can use this codes: =============================== In C: #include <stdio.h> int main() { int a, b, c, max = 0; scanf("%d %d %d", &a,&b,&c); max = b; if(a>b){ max = a; if(c>a){ max = c; } } printf("max : %d", max); return 0; } ================================= In C++; #include <iostream> using namespace std; int main() { int a, b, c, max = 0; cin>> a>> b>> c; max = b; if(a>b){ max = a; if(c>a){ max = c; } } cout << "max : "<< max << endl; return 0; } ================ In Java: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input= new Scanner(System.in); int a = input.nextInt(); int b = input.nextInt(); int c = input.nextInt(); int max = c; if(b>c){ max = b; if(a>b){ max = a; } } System.out.println("max : " + max); } }
24th Sep 2021, 6:17 AM
mesarthim
mesarthim - avatar
+ 1
I know that but in question it is mentioned to use nested loop......that is matter of confusion......how can we implement nested loop for 3 no.s.......still thank you for your suggestion 😁
24th Sep 2021, 6:06 AM
Sugandha Das
0
We need to find the largest number among 3 no.s for example 73 47 52 are 3 no.s here we have to find that 73 is largest number using nested loop...... I am unable to solve this........is it that can we use an integer array?
24th Sep 2021, 5:50 AM
Sugandha Das
0
Yes use of an array is a possibility. But for a 1D array (your example of 3 values) there's no need for nested loop. A regular loop will do.
24th Sep 2021, 6:01 AM
Ipang