Program to find Largest and Smallest number in array solution using c language--programming_info problem 11

Program to find Largest and Smallest number in array.

This above example is just a reference picture. don't
think it as an input of an array.
you can give your own input.
#include<stdio.h>
#include<conio.h>

void main()
{
    int a[50], size, i, largest, smallest;
    clrscr();

    printf("Enter the size of the array : ");
    scanf("%d", &size);

    for (i = 0; i < size; i++)
    {
        printf("Enter element %d in to the array : ", i);
        scanf("%d", &a[i]);
    }

    largest = a[0];
    for (i = 1; i < size; i++)
    {
        if (largest < a[i])
        {
            largest = a[i];
        }
    }
    printf("Largest element : %d", largest);

    smallest = a[0];
    for (i = 1; i < size; i++)
    {
        if (smallest > a[i])
        {
            smallest = a[i];
        }
    }
    printf("\nSmallest element : %d", smallest);
    getch();
}
Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support