Предмет: Информатика,
автор: vnedyak1
программа в с# которая в цикле введет 8 значений и посчитает количество негативных чисел или равных нулю?
Ответы
Автор ответа:
0
const int neededInputs = 8;
try
{
int counterNegativeNumbers = 0;
int counterInLoop = 0;
while (counterInLoop < neededInputs)
{
Console.WriteLine("Type a number, please ");
int number = Int32.Parse(Console.ReadLine());
if(number < 1)
counterNegativeNumbers++;
counterInLoop++;
}
Console.WriteLine(String.Format("You`ve written {0} negative or zero numbers", counterNegativeNumbers));
}
catch(FormatException ex)
{
Console.WriteLine("Invalid format of the number");
}
try
{
int counterNegativeNumbers = 0;
int counterInLoop = 0;
while (counterInLoop < neededInputs)
{
Console.WriteLine("Type a number, please ");
int number = Int32.Parse(Console.ReadLine());
if(number < 1)
counterNegativeNumbers++;
counterInLoop++;
}
Console.WriteLine(String.Format("You`ve written {0} negative or zero numbers", counterNegativeNumbers));
}
catch(FormatException ex)
{
Console.WriteLine("Invalid format of the number");
}
Похожие вопросы
Предмет: Русский язык,
автор: Аноним
Предмет: Қазақ тiлi,
автор: yoongixshine
Предмет: Английский язык,
автор: ebrehpactamah85
Предмет: Литература,
автор: AleksandrSemenov
Предмет: Математика,
автор: никита4567