+ 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?

20th Jul 2020, 3:39 AM
Amal Babu
Amal Babu - avatar
4 Respuestas
+ 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 )
20th Jul 2020, 3:48 AM
Arsenic
Arsenic - avatar
+ 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
20th Jul 2020, 3:59 AM
Akash
Akash - avatar
+ 2
Glad to help.
20th Jul 2020, 4:07 AM
Akash
Akash - avatar
+ 1
Thanks Akash , it works!!
20th Jul 2020, 4:04 AM
Amal Babu
Amal Babu - avatar