Hướng dẫn 15. python program for cube sum of first n natural numbers - 15. Chương trình python cho tổng lập phương của n số tự nhiên đầu tiên
Ngày đăng:
07/10/2022
Trả lời:
0
Lượt xem:
106
Xem thảo luận Show Cải thiện bài viết Lưu bài viết Xem thảo luận Cải thiện bài viết Lưu bài viết Đọc Input : n = 5 Output : 225 13 + 23 + 33 + 43 + 53 = 225 Input : n = 7 Output : 784 13 + 23 + 33 + 43 + 53 + 63 + 73 = 784
Python3Python3Bàn luận In tổng của chuỗi 13 + 23 + 33 + 43 +. Ví dụ:
2250 2251
2253 2254 2255 2256 2257 2258 2259 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7840__18 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7842 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7843 sum For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7840 2250 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7847 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7848 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7847 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7848__ 2258 2259
225 2255 2250 2257efficient solution is to use direct mathematical formula which is (n ( n + 1 ) / 2) ^ 2 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 784 Python3Python3Bàn luận In tổng của chuỗi 13 + 23 + 33 + 43 +. Ví dụ:
For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7843 sum For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7840 2250 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7847 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7848 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7847 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7848__ 2258 2259 Output: 225
2253 sum How does this formula work? We can prove the formula using mathematical induction. We can easily see that the formula holds true for n = 1 and n = 2. Let this be true for n = k-1.Let the formula be true for n = k-1. Sum of first (k-1) natural numbers = [((k - 1) * k)/2]2 Sum of first k natural numbers = = Sum of (k-1) numbers + k3 = [((k - 1) * k)/2]2 + k3 = [k2(k2 - 2k + 1) + 4k3]/4 = [k4 + 2k3 + k2]/4 = k2(k2 + 2k + 1)/4 = [k*(k+1)/2]2
Python3Python3Bàn luận In tổng của chuỗi 13 + 23 + 33 + 43 +. Ví dụ:
2250 2251
2253 2254 2255 2256 2257 2258 2259 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7840__18 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7842
For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7843 sum For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7840 2250 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7847 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7848 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7847 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7848__ 2258 2259 Output: 225
Python322507 2250 2257 22523 2250 2251 2255 2250 2257
22523 2250 22523 For n = 5 sum by formula is (5*(5 + 1 ) / 2)) ^ 2 = (5*6/2) ^ 2 = (15) ^ 2 = 225 For n = 7, sum by formula is (7*(7 + 1 ) / 2)) ^ 2 = (7*8/2) ^ 2 = (28) ^ 2 = 7840 22541 22542 22543 2253 2258 22546 Đầu ra: Làm thế nào để bạn tìm thấy tổng số khối N số tự nhiên trong Python?Phương pháp: Tìm tổng khối của N Số tự nhiên đầu tiên bằng cách sử dụng hàm tích hợp pow ().Hàm pow () tìm thấy khối lập phương của một số bằng cách đưa ra các giá trị của i và số.Ex: Pow (i, 3).using built-in function pow(). The pow() function finds the cube of a number by giving the values of i and number. ex: pow(i,3).
Tổng khối lượng của N Số tự nhiên đầu tiên là bao nhiêu?Chúng ta biết rằng tổng khối của n số tự nhiên đầu tiên là = (n (n+1)/2) 2.(n(n+1)/2)2.
Tổng số khối của 15 số tự nhiên đầu tiên là bao nhiêu?Tổng khối của 15 số tự nhiên đầu tiên là bao nhiêu?Tổng khối lượng của 15 số tự nhiên đầu tiên là 14400. Chúng ta hãy xem xét cách chúng ta có câu trả lời.Tổng khối của 15 số tự nhiên = [152 (15 + 1) 2]/4 = (225 × 256)/4 = 14400.14400. Let us look at how we got the answer. Sum of cubes of 15 natural numbers = [152 (15 + 1)2]/4 = (225 × 256)/4 = 14400.
Làm thế nào để bạn tìm thấy tổng của n số tự nhiên đầu tiên trong Python?Đầu ra chương trình cũng được hiển thị bên dưới ... n = int (input ("nhập một số:")) sum1 = 0 while (n> 0): sum1 = sum1+n n = n-1 in ("tổng của n số tự nhiên đầu tiên là", sum1). Trường hợp 1: Nhập một số: 18 Tổng số n tự nhiên đầu tiên là 171 Trường hợp 2: Nhập một số: 167 Tổng số N Số tự nhiên đầu tiên là 14028 .. |