top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C program to find and print second largest digit in the given number?

0 votes
4,006 views

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

posted Apr 4, 2017 by anonymous

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

1 Answer

0 votes
#include<stdio.h>
int main(void)
{
        int num,res=0,minDigit,maxDigit;
        printf("Enter a number\n");
        scanf("%d",&num);
        maxDigit=minDigit=num%10;
        while(num)
        {
                res=num%10;
                if(res<minDigit)
                        minDigit=res;
                else if(res>maxDigit)
                        maxDigit=res;
                num=num/10;
        }
        printf("Min Digit = %d\nMax Digit = %d\n",minDigit,maxDigit);
        return 1;
}
answer May 11, 2017 by Chirag Gangdev
...