Write a C# program to count the number of negative numbers in a sequence of numbers the user inputs. In this solution, before reading the numbers, ask the user to input how many numbers will be input.
1
Expert's answer
2013-02-05T09:30:33-0500
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Egative_numbers_in_a_sequence { class Program { static void Main(string[] args) { int number=0; int countofnegetivenumbers = 0; int inputnumber; Console.Write("How many numbers will be input "); number = int.Parse(Console.ReadLine()); for (int i = 0; i < number; i++) { Console.Write("Enter number: "); inputnumber = int.Parse(Console.ReadLine()); if (inputnumber < 0) { countofnegetivenumbers++; } } Console.Write("The number of negative numbers in a sequence are: " + countofnegetivenumbers.ToString()); Console.ReadKey();
Comments
Leave a comment