Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define NUM1 3
- #define NUM2 5
- int main()
- {
- int x, y, z, num1total, num2total, num3total, total1, total2, total3, total;
- total1=0;
- total2=0;
- total3=0;
- x=0;
- y=0;
- z=0;
- // Find the multiples of 3 and add them together
- while ( x <= 333 ) {
- num1total=NUM1 * x;
- total1=total1 + num1total;
- ++x;
- }
- // Find Multiples of 5 and add them
- while ( y <= 199 ) {
- num2total=NUM2 * y;
- total2=total2 + num2total;
- ++y;
- }
- // get rid of multiples of 15 to get rid of double counting
- while (z <= 66) {
- num3total=15 * z;
- total3=total3 + num3total;
- ++z;
- }
- total= total1 + total2;
- total= total - total3;
- printf("The total sum of the natural numbers is:%d\n", total);
- printf("Total1 is:%d\n Total2 is:%d\n", total1, total2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement