CODE
//variable declaration//
int[] num;
int size,largest = 0,temp=0,smallest;
bool duplicate;
//input size//
Console.Write("Input Size: ");
size = int.Parse(Console.ReadLine());
num = new int[size];
smallest = num[0];
for (int i = 0; i < size; i++)
{
do
{
duplicate = false;
Console.Write("Input a number[" + i + "]: ");
num[i] = int.Parse(Console.ReadLine());
//duplicate//
for (int n = 0; n < i; n++)
{
if (num[i] == num[n])
{
duplicate = true;
Console.WriteLine("It Is A Duplicate");
}
}
//largest and smallest//
if (num[i] > largest)
{
largest = num[i];
}
else if (num[i] < smallest)
{
smallest = num[i];
}
temp = smallest;
} while (duplicate == true);
}
Console.WriteLine("Largest is: " + largest);
Console.WriteLine("Smallest is: "+temp );
Console.ReadKey();
I removed the int smallest = n[0];
but somehow the output for the smallest value turns out to be zero no matter what the input is...
can someone know whats the problem with my code for smallest value...
if you can improvise my code that would be really nice...
my code traps the duplicate get the largest and the size of the array depends on the size input... thanks...