Write a for statement to add all the numbers divisible by 3 or 5 between 1 and 1000.
#include <iostream>Â
using namespace std;Â
int main(){Â
int sum=0;
//add all the numbers divisible by 3 or 5 between 1 and 1000.
for(int i=0;i<=1000;i++){
if(i%3==0 || i%5==0){
sum+=i;
}
}
cout<<"Sum: "<<sum<<"\n\n";
cin>>sum;
return 0;
}
Comments
Its good
Leave a comment