Write a program to find biggest of 10 given numbers using an efficient way(plzzz tell me itssss really urgent)
Anonymous:
C++ or Java
Answers
Answered by
0
#include <iostream>
using namespace std;
int main()
{
int i, n=10;
float arr[11];
for(i = 0; i < n; ++i)
{
cout << "Enter Number " << i + 1 << " : ";
cin >> arr[i];
}
for(i = 1;i < n; ++i)
{
if(arr[0] < arr[i])
arr[0] = arr[i];
}
cout << "Largest element = " << arr[0];
return 0;
}
Hope it helps
public class Largest_Number
{
public static void main(String[] args)
{
int n, max;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of elements in the array:");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter elements of array:");
for(int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
max = a[0];
for(int i = 0; i < n; i++)
{
if(max < a[i])
{
max = a[i];
}
}
System.out.println("Maximum value:"+max);
}
}
public class Largest_Number
{
public static void main(String[] args)
{
int max, n=10;
int a[11];
System.out.println("Enter elements of array:");
for(int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
max = a[0];
for(int i = 0; i < n; i++)
{
if(max < a[i])
{
max = a[i];
}
}
System.out.println("Maximum value:"+max);
}
}
Similar questions
Math,
7 months ago
English,
7 months ago
Accountancy,
7 months ago
Math,
1 year ago
English,
1 year ago
Social Sciences,
1 year ago
Math,
1 year ago