Thursday, 24 July 2014

C program to find the smallest and largest of an integer

/* Program to find the smallest and largest of an integer */

#include<stdio.h>
#include<conio.h>
void main()
{
 int n,max,min,rem;
 clrscr();
 printf("Enter a number:");
 scanf("%d",&n);
 max=min=n%10;
 while(n!=0)
{
 rem=n%10;
 if(rem>=max)
   max=rem;
 else if(rem<=min)
   min=rem;
 n=n/10;
}
printf("\nLargest=%d\nSmallest=%d",max,min);
getch();
}


No comments:

Post a Comment