Tuesday, 5 June 2012

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

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10],i,j,n,count[10]=0;
 printf("\nEnter the capacity of list you are willing to give");
 scanf("%d",&n);
 printf("\nEnter  %d values");
 for(i=0;i<n;i++)
 {
 scanf("%d",&a[i]);
 }

 for(i=0;i<n;i++)
 {
   for(j=0;j<n;j++)
   {
    if(a[i]<=a[j])
    {
    break;
    }
   else
   count[i]++;
   }
 }
printf("\nThe greatest value among the given list is");
for(i=0;i<n;i++)
if(count[i]==n)
printf("%d",count[i]);
}

No comments:

Post a Comment