Question

The code needs to be in C #. Write a simple program that reads from the...

The code needs to be in C #.

Write a simple program that reads from the console a set of numbers and prints back onto the console the smallest number from the collection

Homework Answers

Answer #1
using System;

class Program
{
    static void Main() {
        int min;
        string s;
        Console.WriteLine("Enter space separated numbers: ");
        s = Console.ReadLine();

        string[] splits = s.Split(' ');

        int[] numbers = new int[splits.Length];

        for (int i = 0; i<numbers.Length; i++)
        {
            string tmp=splits[i].Trim();
            numbers[i] = int.Parse(tmp);
        }
        
        min = numbers[0];
        for(int i = 1;i<numbers.Length;i++){
            if(min > numbers[i]){
                min = numbers[i];
            }
        }
        Console.WriteLine("Smallest number = "+min);

    }
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The code needs to be in C #. You can define the upper and lower bounds....
The code needs to be in C #. You can define the upper and lower bounds. Q. You are given a lower and an upper bound for a range of integer numbers. Write a program that prints the range of numbers in the reverse order and prints it back on the original order.
Write a simple TCP program for a client that reads a line of text from its...
Write a simple TCP program for a client that reads a line of text from its standard input (keyboard) and sends the line out its socket to the server. The server reads the line from the socket and prints it in its standard output (screen). The server then reads a line from its standard input (keyboard) and sends it out its socket to the client. When the client sends “!” the server should reply back “bye” to the client and...
Its a c++ task. Write a program that reads 10 integers from the user into an...
Its a c++ task. Write a program that reads 10 integers from the user into an array and uses a function arrayMinimum that accepts an integer array a along with its size arraySize as parameters and returns the smallest array element. The program then outputs the result (the smallest array element).
Shell Programming Question: Write a shell program that reads a set of integers {125, 0, 122,...
Shell Programming Question: Write a shell program that reads a set of integers {125, 0, 122, 129, 0, 117}, and then prints a set of integers {125, 122, 129, 117}. Tips: Remove zeros **Write comments for code
Write a C++ program that reads two integers from the user. The program should tell whether...
Write a C++ program that reads two integers from the user. The program should tell whether the two numbers are equal or not.
Write a program in C that does the following: Reads 10 real numbers from the keyboard...
Write a program in C that does the following: Reads 10 real numbers from the keyboard using a loop and displays the sum of the numbers and the sum of the square of the numbers.
(C++) 5.15 LAB: Two smallest numbers with arrays Write a program that reads a list of...
(C++) 5.15 LAB: Two smallest numbers with arrays Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The input begins with an integer indicating the number of integers that follow. Ex: If the input is: 5 10 5 3 21 2 the output is: 2 3 You can assume that the list of integers will have at least 2 values. To achieve the above, first read the integers...
C++ INSTRUCTIONS Problem Specification : Write a program that reads a group of numbers from the...
C++ INSTRUCTIONS Problem Specification : Write a program that reads a group of numbers from the user and places them in an array of type float. Once the numbers are stored in the array, the program should average and print the result. Use pointer notation wherever possible. Program Output (with Input Shown in Bold): Enter number: 2 Enter another (y/n)? y Enter number: 4 Enter another (y/n)? y Enter number: 6 Enter another (y/n)? y Enter number: 8 Enter another...
Perl language and by using VS Code: Write a program that reads a number, adds up...
Perl language and by using VS Code: Write a program that reads a number, adds up the cube of all the digits, and displays the result. Run your code with the following test number: 1242 It should give 81. Please include screenshots of your outputs.
Write a program that reads a word and then prints the word in reverse separated by...
Write a program that reads a word and then prints the word in reverse separated by a comma. 3 pts Note: No comma at the end of the reversed word. Enter word: Harry The reversed word is: y,r,r,a,H Python keep it simple