xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
// input
int n;
cin >> n;
int arr[10];
int maxNum;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
// Algo
maxNum = arr[0];
for (int i = 0; i < n; i++)
{
if (maxNum < arr[i])
{
maxNum = arr[i];
}
}
// output
cout << maxNum;
// for (int i = 0; i < n; i++)
// {
// cout << arr[i] << " ";
// }
return 0;
}
xxxxxxxxxx
const getLargest = (arr) =>
arr.reduce((largest, num) => Math.max(largest, num));
const arr = [13, 7, 11, 3, 9, 15, 17];
console.log(getLargest(arr)); // 17
xxxxxxxxxx
function maisBaratosQue(valor, precos) {
return precos.filter(p => p <= valor);
}
xxxxxxxxxx
#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}
// storing the largest number to arr[0]
for (int i = 1; i < n; ++i) {
if (arr[0] < arr[i]) {
arr[0] = arr[i];
}
}
printf("Largest element = %.2lf", arr[0]);
return 0;
}
xxxxxxxxxx
// first of all, i write a forEach loop function
// raw fanction
function getArrayLargestElement(array) {
let largestElement = "";
array.forEach(largest);
function largest(word) {
if (word.length > largestElement.length) {
largestElement = word;
}
}
return largestElement;
}
const banglaGit = [
"amader",
"sonar",
"bangladesh",
"ami tomay",
"onek ",
"valo basi",
];
console.log(getArrayLargestElement(banglaGit));
// es6 arrow function
const getLargestArrowFunc = (array) => {
let largest = "";
array.forEach((word) => {
if (word.length > largest.length) {
largest = word;
}
});
return largest;
};
console.log(
getLargestArrowFunc(["hello", "world", "md yeamin", "i'm", "here"])
);
xxxxxxxxxx
import java.util.*;
public class tuf {
public static void main(String args[]) {
int arr1[] = {2,5,1,3,0};
System.out.println("The Largest element in the array is: " + sort(arr1));
int arr2[] = {8,10,5,7,9};
System.out.println("The Largest element in the array is: " + sort(arr2));
}
static int sort(int arr[]) {
Arrays.sort(arr);
return arr[arr.length - 1];
}
}
xxxxxxxxxx
#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}
// storing the largest number to arr[0]
for (int i = 1; i < n; ++i) {
if (arr[0] < arr[i]) {
arr[0] = arr[i];
}
}
printf("Largest element = %.2lf", arr[0]);
return 0;
}
xxxxxxxxxx
//FOR MIN AND MAX BOTH
#include <iostream>
using namespace std;
int main()
{
int size;
cout << "Enter size of array: ";
cin >> size;
int numbers[size];
for (int i = 0; i <= size; i++)
{
cout << "Enter an Integer: ";
cin >> numbers[i];
}
int minimum = numbers[0];
int maximum = numbers[0];
for (int i = 0; i < size; i++)
{
if (minimum > numbers[i])
{
minimum = numbers[i];
}
if (maximum < numbers[i])
{
maximum = numbers[i];
}
}
cout << "Maximum: " << maximum << endl;
cout << "Minimum: " << minimum << endl;
return 0;
}