using System;
namespace Example
{
class SecondLargestNum
{
static void Main()
{
int largeNum = 0;
int smallNum = 0;
Console.WriteLine("Enter the
numbers");
int num = int.Parse(Console.ReadLine());
while (num > 0)
{
var mod = num % 10;
if (mod > largeNum)
{
smallNum = largeNum;
largeNum = mod;
}
if (mod != largeNum && smallNum <
mod)
{
smallNum = mod;
}
num = num / 10;
}
Console.WriteLine("Second largest
number {0}: ", smallNum);
Console.ReadLine();
}
}
}
Output:
No comments:
Post a Comment