C Programming

C Program – Find Largest and Smallest number in an Array

C Program to find the largest and smallest number in an array.

Largest and Smallest number in an Array :

SmallLargeElements.c
#include<stdio.h>
int main(void)
{
    int i,int_arr[10]={6,4,5,0,2,-1,10,-5,15,9};
    int small,large;
    small=large=int_arr[0];
    for(i=1; i<10; i++)
    {
        if(int_arr[i] < small)
            small=int_arr[i];
        if(int_arr[i] > large)
            large=int_arr[i];
    }
    printf("Smallest Element : = %d\nLargest Element : = %d\n",small,large);
    return 0;
}

Output:

Terminal
Smallest Element : = -5
Largest Element : = 15

Happy Learning :)

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Ask a question or leave a comment