Hello, I’m working on this task:
Write a program that reads integer count and then reads count integer numbers from the console and outputs their minimum. Example:
Here is my code:
static void Main(string args)
int count = int.Parse(Console.ReadLine());
int sum = 0;
for (int i = 1; i <= count; i++)
int cInteger = int.Parse(Console.ReadLine());
if(i == count && cInteger < sum)
Can anyone please help me to solve it?
Can’t get my head around finding the min number.
Hi and welcome to Codeasy!
Your code is very close to be finished.
First, create a variable to hold the result. Before the loop, you should have something like this:
int min = int.MaxValue; // Any number bigger than numbers in the input will suffice
sum variable, as you don’t need to calculate the sum.
Then, when you compare cInteger and sum, compare it with min instead, and if cInteger is smaller - reassign min:
min = cInteger;
The last step - output
min after the loop. And that’s it! Let me know if it worked or if you have any further questions.
Did as you adviced. thank you very much!
Your advice was very helpful
Thank you, WorkerOfSecrets I’m glad that the advice was helpful. Don’t hesitate to create more topics, it helps the forum to grow