+ 1
finding odd numbers using for loop,confused
int number = Convert.ToInt32(Console.ReadLine()); //your code goes here for(int i = 1; i <= number&&i%2!=0; i+=2) { Console.Write(
quot;{i}"); }6 Respostas
+ 6
krishnasavera ,
the issue is that the output inside the loop requires a *space* after each number (see the output sample in the task description). so the output should be done like:
...
Console.Write(quot;{i} ");
... ^
an other hint: (this is not an error)
in this line:
...
for(int i = 1; i <= number&&i%2!=0; i+=2)
...
the *modulo division* is not required necessarily, since we start the variable `i` with 1 and add +2 in each loop iteration. this generates only odd numbers.
for the result is makes no difference, but could be done like:
...
for(int i = 1; i <= number; i+=2)
...
+ 4
krishnasavera ,
can you post your current / last code?
+ 4
krishnasavera ,
that is what i have told you in my post ...
+ 1
Solved it finally the solution is missing space which test cases failed
0
The test cases are failing
0
Got the answer