top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

0 votes
1,351 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 Google+ Share Button LinkedIn Share Button Multiple Social 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
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...