Pages

Visitors

Sunday, 25 December 2011

Smallest and Largest in an array of numbers


#include <stdio.h>

void main()

{
    int a[10],n,i,min=99999,max=-99999;

    printf("enter n: ");

    scanf("%d",&n);

    printf("Enter n elements : ");

    for (i=0;i<n;i++)

    scanf("%d",&a[i]);

    for(i=0;i<n;i++)
    {
        if(a[i]<min)

        min = a[i];
    }

    for(i=0;i<n;i++)

    {
        if(a[i]>max)

        max = a[i];
    }

    printf("smallest value is %d and largest value is %d.",min,max);

    getch();


}

No comments:

Post a Comment