Q.Write an algorithm that reads numbers repeatedly until 0 (zero)
is entered, find and display the smallest and largest number. Use while
loop statement.
#include<stdio.h>
#include<conio.h>
int x,lnum,snum;
void main()
{
printf("Enter the number");
scanf("%d",&x);
lnum=x;
snum=x;
while(x!=0)
{
if(x>lnum)
lnum=x;
else if(x<snum)
snum=x;
printf("Enter the number");
scanf("%d",&x);
}
printf("\nLarger %d",lnum);
printf("\nSmaller %d",snum);
getch();
}
No comments:
Post a Comment