img
Question:
Published on: 22 December, 2024

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

Answer:
#include <stdio.h> 
#include <conio.h>

void main()
{
    int i,n,small=0,large=0; 
    int a[30];

    clrscr();
    printf("\n Enter size of the array:"); 
    scanf("%d",&n);

    printf("\n Enter values in array elements:"); 
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    small = a[0]; 
    for(i=0;i<n;i++)
    {
        if(small > a[i]) 
            small = a[i];
    }
    printf("\n The smallest element in given array is %d",small);

    large=0;
    for(i=0;i<n;i++)
    {
        if(large < a[i]) 
            large = a[i];
    }
    printf("\n The largest element in given array is %d",large);

    printf("\n :End of the Main Program:"); 
    getch();
}

Random questions