Advertisement
Guest User

Extra Credit

a guest
Feb 7th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #define NUM1 3
  3. #define NUM2 5 
  4. int main()
  5. {
  6.     int x, y, z, num1total, num2total, num3total, total1, total2, total3, total;
  7.     total1=0;
  8.     total2=0;
  9.     total3=0;
  10.     x=0;
  11.     y=0;
  12.     z=0;
  13.     // Find the multiples of 3 and add them together
  14.     while ( x <= 333 ) {
  15.          num1total=NUM1 * x;
  16.          total1=total1 + num1total;
  17.          ++x;
  18.     }
  19.     // Find Multiples of 5 and add them
  20.     while ( y <= 199 ) {
  21.          num2total=NUM2 * y;
  22.          total2=total2 + num2total;
  23.          ++y;
  24.     }
  25.     // get rid of multiples of 15 to get rid of double counting
  26.     while (z <= 66) {
  27.         num3total=15 * z;
  28.         total3=total3 + num3total;
  29.         ++z;
  30.     }
  31.     total= total1 + total2;
  32.     total= total - total3;
  33.    
  34.     printf("The total sum of the natural numbers is:%d\n", total);
  35.     printf("Total1 is:%d\n Total2 is:%d\n", total1, total2);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement