Jump to content

c problem

- - - - -

  • Please log in to reply
3 replies to this topic

#1
mircea2011

mircea2011

    Newbie

  • Members
  • Pip
  • 8 posts
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);
}

#2
Roman Y

Roman Y

    Programmer

  • Members
  • PipPipPipPip
  • 189 posts
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
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
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
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US

fread said:

Next time Highlight you code and click #. Its called a code tag. Makes your code easier to read. :thumbup:

The

Quote

... Highlight ...
another word for that is 'select' , in case that makes more sense.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users