The manager of the company has informed his assistant to enter the age
of all the workers working in production department. Among all he has to
find the employee with maximum age employee. Help the manager to
find the maximum age employee by storing the all age of all employee in
1D array dynamically. Use functions to solve the task.
Input Format
19 21 22 23 18
Constraints
All numbers should be greater than 0.If constraints are not matched then
display "wrong input"
Output Format
23
using System;
using System.Collections.Generic;
namespace App
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter numbers: ");
string[] values = Console.ReadLine().Split(' ');
int maxValue = int.Parse(values[0]);
for (int i = 0; i < values.Length; i++)
{
int number = int.Parse(values[i]);
if (number < 0)
{
maxValue = -1;
break;
}
else {
if (number > maxValue)
{
maxValue = number;
}
}
}
if (maxValue != -1)
{
Console.WriteLine("Max number is: {0}", maxValue);
}
else {
Console.WriteLine("wrong input");
}
Console.ReadLine();
}
}
}
Comments
Leave a comment