r/CodingHelp • u/perpetually_annoyed • Jan 23 '22
[Random] Need help as a beginner in flowchart self learn. To print even numbers till given N. Check if it is correct and also i was thinking wt will happen and wt changes shud be made if the user gives N as 1. The first condition will fail and it will go end n go blank. ???
2
u/Luc_Studios Jan 23 '22
dont write the if statement so crammed into a tight space. By that u will only confuse urself in long term. At least that's what is the case for me
2
u/Ultraok Jan 24 '22
Just loop until N/2 and print A*2. You will get even values.
1
u/MamadouHD Jan 24 '22
A*2 will skip some even numbers, shouldn't he go with A+2 instead? something like if A < N then A+2 and print A
1
u/Ultraok Jan 24 '22
No it only shows all even numbers, just checked it.
1
u/MamadouHD Jan 24 '22
How the hell did 6 showed up? If you start at 2, wouldnt it be like 2, 4, 8, 16, .... ?
1
u/Ultraok Jan 24 '22 edited Jan 24 '22
No, loop from 1 to n/2 will contain 1,2,3,4...n/2
So multiplying by 2 will give 2,4,6,8...n.
1
2
3
u/funkym00se Jan 23 '22
You'll have to loop the condition A<=N, if false end it , else go to next step then check the condition A%2==0, if true print A, and no matter it true or false increment A with 1 i.e.A=A+1