Hello
First of all, you should put the WHILE on IF(num>=0), then you should make your number positive in ELSE. for example, I do (num=num-2*(num);) this. that works for me. absolutely you can write this very better with functions.
#include<stdio.h>
int main()
{
int num,r=0,max=0;
scanf("%d",&num);
if(num>=0)
{
while(num>0)
{
r=num%10;
if(r>=max)
{
max=r;
}
num=num/10;
}
}
else
{
num=num-2*(num);
while(num>0)
{
r=num%10;
if(r>=max)
{
max=r;
}
num=num/10;
}
}
printf("%d",max);
return 0;
}