Sunday, May 5, 2013

Program to find the LARGEST and smallest number in the given array


/*Write a C program to find both the LARGEST and SMALLEST number in a
list of integers
*/

#include<stdio.h>

main()
{
    int a[10],n,i,small,large;
    clrscr();
    printf("Enter how many integers:");
    scanf("%d",&n);
    printf("Enter %d integers:",n);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    small=large=a[0];
    for(i=0;i<n;i++)
    {
        if(a[i]<small)
        small=a[i];
        if(a[i]>large)
        large=a[i];
    }
    printf("\n\t LARGEST %d",large);
    printf("\n\t small   %d",small);
    getch();
}

output:

Enter how many integers:10
Enter 10 integers:
20
30
50
10
256
4
178
25
45
24

         LARGEST 256
         small   4

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More