Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Get the Largest Element of an Array, array js

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
Comment

Find the biggest element in the array


#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;
}
Comment

function that search a biggest value in array javascript

function maisBaratosQue(valor, precos) {
   return precos.filter(p => p <= valor);
}
Comment

largest number of array

#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;
}
Comment

largest element in array

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];
  }
}
Comment

get biggest element in array javascript

// 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"])
);
Comment

largest number of array

#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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ string split 
Cpp :: priority queue in c++ 
Cpp :: C++, for-loop over an array array 
Cpp :: new line in c++ 
Cpp :: c++ char array size 
Cpp :: c++ erase remove 
Cpp :: operand-- c++ 
Cpp :: c++ Program to check if a given year is leap year 
Cpp :: length of array c++ 
Cpp :: cpp lambda function 
Cpp :: C++ continue with for loop 
Cpp :: binary search in c++ 
Cpp :: cpp define 
Cpp :: find a number in vector c++ 
Cpp :: how to use command line arguments with integers in c++ 
Cpp :: hashmap c++ 
Cpp :: find function in c++ 
Cpp :: cpp linked list 
Cpp :: exponent power of x using c c++ 
Cpp :: walk filesystem in c++ 
Cpp :: how to change the value of a key in hashmp in c++ 
Cpp :: how to convert hexadecimal to decimal in c++ 
Cpp :: z transfrom mathlab 
Cpp :: what is the default include path in ubuntu c++ 
Cpp :: c++ pop string from vector 
Cpp :: how to declare an enum variable c++ 
Cpp :: c++ include < vs "" 
Cpp :: what is the time complexitry of std::sort 
Cpp :: why return 0 in int main 
Cpp :: how to rotate a matrix 90 degrees clockwise 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =