S
S
SlideUp2017-09-11 20:50:51
C++ / C#
SlideUp, 2017-09-11 20:50:51

How to organize instructions?

Hello ripple. I'm learning C# little by little and doing different tasks.
For example - From the interval [-X, X] (variable X - entered from the keyboard) find the number of positive numbers that are multiples of 3 and the number of negative even numbers.
I found positive ones, but how else can I find negative ones in the same place, is it possible to prescribe the condition in else if that i % 2 == 0 && i < 0, am I thinking right?
Here is the initial code -

Console.WriteLine("Input X number");
int X = int.Parse(Console.ReadLine());
for(int i = -X; i < X;  i++ ){
      if(i % 3 == 0 && i > 0){
          Console.WriteLine("Result is = " + i);
      }
}

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Amfore, 2017-09-11
@SlideUp

Yes, right.
Only if you need to find at the same time,

and the number of positive numbers that are multiples of 3, and the number of negative even numbers.

you need instead of else if just if.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question