Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Find the difference between the sum of the squares of the first one
- hundred natural numbers and the square of the sum. */
- /* Solution #1 */
- #include <stdio.h>
- int main()
- {
- int i;
- int natNumSum = 0, squareNumSum = 0;
- for(i = 1; i < 101; i++)
- natNumSum += i;
- for(i = 1; i < 101; i++)
- squareNumSum += i * i;
- printf("%d\n", natNumSum * natNumSum - squareNumSum);
- return(0);
- }
- /* 25164150 */
- /* Solution #2 */
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int i;
- double natNumSum = 0;
- double squareNumSum = 0;
- for(i = 1; i < 101; i++)
- natNumSum += i;
- for(i = 1; i < 101; i++)
- squareNumSum += pow(i, 2);
- printf("%.0f\n", pow(natNumSum, 2) - squareNumSum);
- return(0);
- }
- /* 25164150 */
Add Comment
Please, Sign In to add comment