This is the best logic building program related to arrays for beginners. The program will find the second greatest number in a given array.
Source Code
using System;
using System.Collections.Generic;
using System.Text;
namespace assad
{
class secondGreatest
{
// /*
static void Main(string[] args)
{
welcomeScrean();
secondGreatestFoo();
int toPause = Console.Read();
}
private static void welcomeScrean()
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("\t*******************************************************" + "\n"
+ "\t*******************************************************" + "\n"
+ "\t** Find **" + "\n"
+ "\t** Second Greatest **" + "\n"
+ "\t** in Array of Numbers **" + "\n"
+ "\t*******************************************************" + "\n"
+ "\t*******************************************************\n\n\n\n");
}
private static void secondGreatestFoo()
{
int max = 0; int num; int secGreatest;
Console.Write("\tEnter the number count : ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\tEnter Your numbes ");
Console.Write("\t");
num = Convert.ToInt32(Console.ReadLine());
secGreatest = num;
max = num;
for (int i = 1; i < n; i++)
{
Console.Write("\t");
num = Convert.ToInt32(Console.ReadLine());
if (num > max)
{
secGreatest = max;
max = num;
}
else
{
if (max == secGreatest)
{
secGreatest = num;
}
if (num < secGreatest)
{
}
else
{
secGreatest = num;
}
}
}
Console.WriteLine("\t");
Console.WriteLine("\tSecond Greatest:" + secGreatest);
}
// */
}
}
0 comments:
Post a Comment