+ 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}"); }

4th Feb 2024, 6:25 PM
krishnasavera
6 odpowiedzi
+ 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) ...
4th Feb 2024, 6:57 PM
Lothar
Lothar - avatar
+ 4
krishnasavera , can you post your current / last code?
5th Feb 2024, 3:51 PM
Lothar
Lothar - avatar
+ 4
krishnasavera , that is what i have told you in my post ...
5th Feb 2024, 4:00 PM
Lothar
Lothar - avatar
+ 1
Solved it finally the solution is missing space which test cases failed
5th Feb 2024, 3:58 PM
krishnasavera
0
The test cases are failing
5th Feb 2024, 7:24 AM
krishnasavera
0
Got the answer
5th Feb 2024, 3:57 PM
krishnasavera