C Program – Find Largest and Smallest number in an Array

By | 2017-09-13T06:32:46+00:00 September 13th, 2017|c-program|0 Comments

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

Largest and Smallest number in an Array :


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

[box type=”success” align=”alignleft” class=”” width=”100%”]

Smallest Element : = -5
Largest Element : = 15

[/box]

Happy Learning 🙂

About the Author:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment