Showing posts with label largest element in an array. Show all posts
Showing posts with label largest element in an array. Show all posts

Saturday, 16 May 2015

Python program to find the largest and smallest element in a list



This is a Python program which finds out the smallest and largest element in the list.Here we use 2 functions min() and max() to check for the smallest and largest element respectively.




PROGRAM :
lst = []
num = int(input('How many numbers: '))

for n in range(num):
    numbers = int(input('Enter number '))
    lst.append(numbers)

print("Maximum element in the list is :", max(lst), "\nMinumim element in the list is :", min(lst))


OUTPUT : 
Python - Largest and Smallest element in a list
 

Similar Programs : 
C program to find the largest element in an array
C program to find the smallest element in an array
Cpp program to find the largest element in an array
Cpp program to find the smallest element in an array
Java program to find the largest  element in an array
Java program to find the smallest element in an array

Thursday, 8 January 2015

Java Program to find the Largest Element in an Array


This is a Java Program which finds the largest element in an array.

Here initially first element in array and  its next element are compared array[0] and array[1] , if array[1] is greater then the value is stored in array[0] and now the second element is increased 2 .3 4 .. until the last element is reached.

PROGRAM :
package codingcorner.in;

import java.util.Scanner;

public class LargestElementArray {
 public static void main(String[] args) {
  int i, n;
  System.out.print("How many numbers ?\t");
  Scanner scan = new Scanner(System.in);
  n = scan.nextInt();
  int array[] = new int[n];
  for (i = 0; i < n; i++) {
   System.out.print("\nEnter number " + (i + 1));
   array[i] = scan.nextInt();
  }
  scan.close();
  for (i = 0; i < n; i++) {
   if (array[0] < array[i])
    array[0] = array[i];
  }
  System.out.print("\nThe largest among the" + n + " numbers is "
    + array[0]);
 }
}

OUTPUT :
Java - Largest Element in an Array

Related Programs:
Sum Of Elements in an array ( Cpp )
Sum Of Elements in an array ( Java)
Largest Element in an array( C )
Largest Element in an array ( Cpp )
Sum Of Elements in an array (C)

C Program to find the Largest Element in an Array


This is a C Program which finds the largest element in an array.

Here initially first element in array and  its next element are compared array[0] and array[1] , if array[1] is greater then the value is stored in array[0] and now the second element is increased 2 .3 4 .. until the last element is reached.

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n;
    printf("How many numbers ?\t");
    scanf("%d",&n);
    int array[n];
    for(i=0;i<n;i++)
    {
        printf("\nEnter number %d: \t",i+1);
        scanf("%d",&array[i]);
    }
    for(i=0;i<n;i++)
    {
        if(array[0]<array[i])
            array[0]=array[i];
    }
    printf("The largest among the %d numbers is %d",n,array[0]);
    return 0;
}
 
OUTPUT :
C - Largest Element in an Array


Similar Programs :
C program to find the smallest element in an array
Cpp program to find the largest element in an array
Cpp program to find the smallest element in an array
Java program to find the largest  element in an array
Java program to find the smallest element in an array
Python program to find the largest and smallest element in a list

Monday, 5 January 2015

Cpp Program to find the Largest Element in an array


This is a Cpp Program which finds the largest element in an array.

Here initially first element in array and  its next element are compared array[0] and array[1] , if array[1] is greater then the value is stored in array[0] and now the second element is increased 2 .3 4 .. until the last element is reached.

PROGRAM :
#include <iostream>

using namespace std;

int main()
{
    int n, array[100],i,sum=0;

    cout << "Enter how many numbers ? :\t" ;
    cin >> n;
    cout << endl;

    for(i=0;i<n;i++)
    {
        cout << "Enter number " << i+1 << " : \t";
        cin >> array[i];
    }

    for(i=0;i<n;i++)
    {
        if(array[0] < array[i])
            array[0] = array[i];
    }

    cout << "The largest among the numbers is : \t" << array[0] << endl;

    return 0;
}

OUTPUT :


Cpp Programming - Largest element in an array