+ 1
Program to find the largest number among 3 numbers using nested loop.
Using C,C++,JAVA
5 Answers
+ 2
Please, show your attempt/code then explain the problem clearly. So, we can help. Thanks for understanding.
Happy coding!
+ 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);
}
}
+ 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 đ
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?
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.