Answer to Question #23640 in C# for Sh

Question #23640
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();



}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS