"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Wednesday, February 24, 2010

WAP to print the highest and the lowest digit present in the number input by user.



#include<iostream.h>
#include<conio.h>

void main()
{
int n;

cout<< "\n Enter a number ";
cin>> n;

int num = n;

int high = n%10, low = n%10, rem;

n = n/10;

for(int i = n; i>=1; i=i/10)
{
rem =  i%10;

if(rem>high)
{
high = rem;
}

if(rem < low)
{
low = rem;
}

}

cout<< "\n The highest digit of "<< num <<" is " << high;
cout<< "\n The lowest digit of "<< num <<" is " << low;

getch();

}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.