Answers for "how to find largest number in array"

6

find maximum number in array

#include <stdio.h>
int main() {
    int i, n;
    float arr[100];
    printf("Enter the number of elements (1 to 100): ");
    scanf("%d", &n);

    for (i = 0; i < n; ++i) {
        printf("Enter number%d: ", i + 1);
        scanf("%f", &arr[i]);
    }

    // storing the largest number to arr[0]
    for (i = 1; i < n; ++i) {
        if (arr[0] < arr[i])
            arr[0] = arr[i];
    }

    printf("Largest element = %.2f", arr[0]);

    return 0;
}
Posted by: Guest on April-28-2020
8

get largest number in array javascript

const array1 = [1, 3, 2];

Math.max(...array1);
// expected output: 3
Posted by: Guest on August-07-2020
0

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;
}
Posted by: Guest on September-05-2021

Code answers related to "how to find largest number in array"

Browse Popular Code Answers by Language