Read an integer up to 9 digits. To display the highest and lowest digit of number.
No output. I don't understand where is my mistake.
#include<stdio.h>
int main()
{
int c, n, min=10, max=0;
long nr;
printf("\n Giva the number nr = ");
scanf("%ld", &nr);
while(nr)
{
c=nr%10;
if(c>max)
max=c;
else if(c<min)
min=c;
n=n/10;
}
printf("\n The highest digit is : %d\n", max);
printf("\n The lowest digit is : %d\n", min);
}
3 replies to this topic
#1
Posted 19 November 2011 - 01:37 AM
|
|
|
#2
Posted 19 November 2011 - 02:27 AM
You're in an infinite loop since nr is never changed. Remove the n from the whole program and replace n=n/10 with nr /= 10;
#3
Posted 19 November 2011 - 06:41 PM
Next time Highlight you code and click #. Its called a code tag. Makes your code easier to read. :thumbup:
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:
#4
Posted 19 November 2011 - 07:12 PM
fread said:
Next time Highlight you code and click #. Its called a code tag. Makes your code easier to read. :thumbup:
The
Quote
... Highlight ...
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









