+ 2
How to print numbers from (-a to a) by excluding multiples of a certain number in C++ ?
I want a simple C++ program to print numbers from -10 to 10 by excluding the multiples of 3 using for loop. Can anyone help me?
4 Respostas
+ 2
You can opt for a brute force method of iterating through the entire range and check for required condition for each and every number.
You can also optimise it by just iterating over positive integers in the given range and double the answer at the end ( but you should also look at the corner cases in this part )
+ 2
To excude a certain type of numbers from a loop you can use if statement with continue statements which lefts the statement after continue and runs the loop again.
https://code.sololearn.com/cbAYetpHqJ6A/?ref=app
+ 2
Glad to help.
+ 1
Thanks Akash , it works!!