Answer to Question #260767 in C++ for abood

Question #260767

Write a for statement to add all the numbers divisible by 3 or 5 between 1 and 1000.


1
Expert's answer
2021-11-03T11:43:53-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

VALENTINA JEROME
18.05.23, 10:18

Its good

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS