23.12.19

FInding largest and smallest number from a list program in c

#include<stdio.h>

void main()

{

int a[50],i,n,large,small;

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

printf("Enter the elements into array to find largest and smallest number");

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

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

large=small=a[0];

for(i=1;i<n;i++)
{
if(a[i]<small)

small=a[i];

}

printf(" The largest number is %d",large);
printf("The smallest number is %d",small);

}


OUTPUT

Enter the size of array 10
Enter the elements into array to find largest and smallest number 12  3  67  90  9  56  34  6  8 12
 The largest number is   90
The smallest number is 3

No comments:

Post a Comment

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...