The sum of the squares of the first ten natural numbers is,

12 + 22 + ... + 102 = 385

The square of the sum of the first ten natural numbers is,

(1 + 2 + ... + 10)2 = 552 = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 (Problem 6)Sum square difference 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <ctype.h>
 4 #include <math.h>
 5   
 6 #define N 100
 7   
 8 int powplus(int n, int k)
 9 {
10     int s=1;
11     while(k--)
12     {
13        s*=n;
14     }
15   return s;
16 }
17   
18 int sum1(int n)
19 {
20    return  powplus((n+1)*n/2,2);
21 } 
22   
23 int sum2(int n)
24 {
25    return (n*(n+1)*(2*n+1))/6;
26 }
27   
28 void solve()
29 {
30      printf("%d\n",sum1(N));
31      printf("%d\n",sum2(N));
32    printf("%d\n",sum1(N)-sum2(N));
33 }
34   
35 int main()
36 {
37   solve();
38   return 0;
39 }

 

Answer:
25164150

 

相关文章:

  • 2021-05-18
  • 2021-09-07
  • 2021-06-21
  • 2022-12-23
  • 2021-06-07
  • 2021-08-26
  • 2022-02-14
  • 2022-01-10
猜你喜欢
  • 2021-10-15
  • 2022-12-23
  • 2021-04-07
  • 2021-09-08
  • 2021-09-28
  • 2021-12-03
相关资源
相似解决方案