showing the odd numbers

So as you can see from the topic im a beginner on c++ and i have an assignment to find the sum between numbers n to m which are divided by 3, my question is how to show the odd numbers here's the code i wrote:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

int main()
{
    int n=5,m=50,s=0;

     while(n<=m)
      {
      if(n%3==0)
      s=s+n;
      n++;
      }
      cout<<"Sum= "<<s;
return 0;
}
To display the numbers that are divisible by 3, you need a cout statement within if range of your if statement at line 10.

1
2
3
4
  if (n%3==0)
  { s=s+n;
     cout << n << endl;
  }



thanks a lot, it really helped me.
Topic archived. No new replies allowed.