### Explaination Help (one more)

What is happening in this code?
why is the `if(a==0 || b==0)`in here and what is it doing?
what is happening in the for loop?

 ``1234567891011121314151617181920212223242526272829`` `````` #include #include void return_sum () //function to find the sum and return the sum { int a,b,i,iSum=0; for (i=1;i<1000;i++) //below 1000 { a = i%3; //multiples for 3 b = i%5; //multiples for 5 if(a==0||b==0) { iSum = iSum+=i; //adding multiples of 3 and 5 } } printf("\nThe sum of all the multiples of 3 or 5 below 1000: %d\n", iSum); //print the sum } int main () { return_sum(); //call to funciton return_sum return 0; } ``````

Thank you!

printf("\nThe sum of all the multiples of 3 or 5 below 1000: %d\n", iSum);
The code is well documented and easy to read. If you can't understand what it is doing, look up the modulus(%) and equality(==) operators and all should become clear.

One silly thing wrong is that it does NOT return the sum but only prints it within the function despite the comment and the name of the function. It's a void function after all. 8^P
It looks like that somebody wrote the program for you made comments for the code but this did not help you to understand what the program does.:)

I would write the program the following way

 ``12345678910111213141516171819202122`` ``````#include #include unsigned int return_sum() //function to find the sum and return the sum { unsigned int sum = 0; for ( unsigned int i = 1; i < 1000; i++ ) { if ( i & 3 ==0 || i % 5 == 0 ) sum += i; } return sum; } int main( void ) { printf( "The sum of all the multiples of 3 or 5 below 1000: %u\n", return_sum() ); return 0; }``````
Thank you everyone for the help! Trying to get better at this ha
Topic archived. No new replies allowed.