Wednesday 21 December 2011


TO FIND LARGEST AND SMALLEST AMONG ‘N’ NUMBERS




#include<stdio.h>
Void main()
{
Int i=1,n;
Float num,large,small;
Printf(“how many numbers?”);
Scanf(“%d”,&n);
If(n<=0)
Printf(“invalid input”);
Else
{
Printf(“enter number-%d:”,i);
Scanf(“%f”,&num);
Large=small=num;
For(;i<n;++i)
{
Printf(“enter number-%d”,i+1);
Scanf(“%f”,&num);
If(large<num)
Large=num;
If(small>num)
Small=num;
}
Printf(“largest=%g\n”,large);
Printf(“smallest=%g”,small):
}
Getch();
}

No comments:

Post a Comment