Guest User

Untitled

a guest
May 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. /*This Code finds the sum of all multiples of 3 or 5 for a given range of numbers. For example for n=10, no. of the multiple of 3 or 5 below 10 are 3,5,6,9 & their sum is 23.*/
  2. int main(){
  3. int t; //Number of test cases
  4. cin >> t;
  5. for(int a0 = 0; a0 < t; a0++){
  6. int sum=0;
  7. int n; //number till which we want to calculate sum.
  8. cin >> n; //eg. 10 or 100
  9. for( int i=0;i<n;i++){
  10. if(i%3==0||i%5==0){
  11. sum+=i; //3,5,6 & 9 are added here
  12. }
  13. }
  14. cout<<sum<<endl; //SUM OF ALL MULTIPLES OF 3 OR 5 RETURNED HERE.
  15. }
  16. return 0;
  17. }
Add Comment
Please, Sign In to add comment