Looping a number and taking away each digit of it is so much fun, but I wanted to try out a much more complex task: getting the largest digit among them all.
Think you can handle the job?
Instructions:
#include<stdio.h>
int main(){
int number,largestDigit=-1,count=0;
int n;
printf("Enter a non-zero positive integer: ");
scanf("%d",&number);
while(number>0){
n=number % 10;
if (n > largestDigit){
count +=1;
largestDigit=n;
}
number = number/10;
}
printf("%d",largestDigit);
getchar();
getchar();
return 0;
}
Comments
Leave a comment