top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find the largest digit in a given number in most efficient way?

+3 votes
474 views

Input: 23678210
Output: 8

posted Oct 4, 2014 by Nimish

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
int main()
{
    int i = 349678;
    int j =0,k;
    while(i){
        if (j < (k=(i %10))) {
            j = k;
        }
        i /=10;
    }
    printf("largest  digit is :%d\n",j);
}
answer Oct 8, 2014 by Bheemappa G
Similar Questions
0 votes

C program to find and print second largest digit in the given number? (without using arrays, functions and using only one loop).

+6 votes

I was trying to get maximum rectangle area for a given histogram but I used brute force approach which have O(n^2) time complexity so I want some better solution using stack so that we could reduce time complexity to O(n) or O(log n ).

...