//C++ program to find sum of numbers from 1 to N
//which are divisible by 3
#include <iostream>
using namespace std;

//Function to calculate sum
//of numbers divisible by 3
int sum(int N) 
{
    int S1;

    S1=((N/3)) * (2*3+(N/3-1)*3)/2;
    
    return S1;    
}
//Driver Code
int main()
{
    int N=20;
    cout<<sum(N);

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: