Not asking for the answer! Rather then having to set up 12 void functions, is it possible to reduce my functions or use the minimum amound of functions tot attain these desired options. Once again, not looking for the answer! If there is how can I do it?
Option Description Output
1 Print all the numbers between 1 and 1000 that are divisible by 1 1 2 3 4 5 … 1000
2 Print all the numbers between 1 and 1000 that are divisible by 2 2 4 6 … 1000
3 Print all the numbers between 1 and 1000 that are divisible by 3 3 6 9 … 999
4 Print all the numbers between 1 and 1000 that are divisible by 4 4 8 12 … 1000
5 Print all the numbers between 1 and 1000 that are divisible by 5 5 10 15 … 1000
6 Print all the numbers between 1 and 1000 that are divisible by 6 6 12 ... 996
7 Print all the numbers between 1 and 1000 that are divisible by 7 7 14 ... 994
8 Print all the numbers between 1 and 1000 that are divisible by 8 8 16 ... 1000
9 Print all the numbers between 1 and 1000 that are divisible by 9 9 18 ... 999
10 Print all the numbers between 1 and 1000 1 2 3 4 5 … 1000
11 Print all the even numbers between 1 and 1000 2 4 6 … 1000
12 Print all the odd numbers between 1 and 1000 1 3 5 … 999
You can write just two functions to solve all the above.
One function can be print_divisible() and the other print_odd().
print_divisible(int n) where n is the number that numbers from 1 to 1000 must divide by exactly.
Then for problems 1 to 9 you can simply give n as 1, 2, 3, ... 9.
Problems 10 and 11 are are problems 1 and 2 repeated.
Problem 12 would use print_odd() instead, where you print numbers that do not divide by 2.
Giblit, I believe I have my code working, but I was working on my fellow classmates code and can't seem to figure out why this is not incrementing by two. In my output, I get the results "2345678.... and not "2468
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void print_divisible()
{
int counter=0;
int k=0;
while(counter<=100)
{
k=counter+2;
cout<<k;
counter++;
}
}