Thursday, 26 January 2012

Write a C program to find both the largest and smallest numbers in a list of integers.

#include<stdio.h>
#include<conio.h>
void main(void)
{
    int a[50], max, min, i, n;
    clrscr( );
    printf("Enter how many integers do u want? :");
    scanf(" %d", &n);
    for( i=0; i< n ; i++)
    {
        printf("\nEnter the %d number: ", i );
        scanf(" %d", &a[ i ]);
        if(i==0)
        {
            max=a[i ]; min=a[i ];
        }
        if(a[ i]>max)
        max= a[i ];
        if(a[i ]< min)
        min= a[i ];
    }
    printf("\n Maximum : %d", max);
    printf("\n Minimum : %d", min);
    getch( );
}

No comments:

Post a Comment