Chương trình tìm tổng của chuỗi 1 + x + x^2+ x^3+. +x^n
Cải thiện bài viết
Lưu bài viết
Thích bài viết
- Độ khó. Trung bình
- Cập nhật lần cuối. 12 tháng 7 năm 2022
Cải thiện bài viết
Lưu bài viết
Cho một số nguyên X, nhiệm vụ là in chuỗi và tìm tổng của chuỗi
Ví dụ.
Đầu vào. X = 2, N = 5
Đầu ra. Tổng = 31
1 2 4 8 16
Đầu vào. X = 1, N = 10
Đầu ra. Tổng = 10
1 1 1 1 1 1 1 1 1 1
Khuyến khích. Vui lòng thử cách tiếp cận của bạn trên {IDE} trước, trước khi chuyển sang giải pháp
Cách tiếp cận. Ý tưởng là duyệt qua chuỗi và tính tổng N số hạng của chuỗi. Thuật ngữ thứ N của chuỗi có thể được tính là.
Số hạng thứ N = [N-1]Số hạng * X
Dưới đây là cách triển khai của phương pháp trên.
C++
// C++ implementation to find
// sum of series of
// 1 + x^2 + x^3 + ....+ x^n
#include
using
namespace
std;
________số 8
// the series and print N terms
// C++ implementation to find
0
// C++ implementation to find
1 // C++ implementation to find
2// C++ implementation to find
3 // C++ implementation to find
4// C++ implementation to find
3 // C++ implementation to find
6
// C++ implementation to find
7
// C++ implementation to find
8// C++ implementation to find
1 // sum of series of
0
// C++ implementation to find
8// sum of series of
2
// C++ implementation to find
8// sum of series of
4// sum of series of
5// sum of series of
6
// C++ implementation to find
8// sum of series of
8
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
0
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
2 // 1 + x^2 + x^3 + ....+ x^n
3
// 1 + x^2 + x^3 + ....+ x^n
4// 1 + x^2 + x^3 + ....+ x^n
5
// 1 + x^2 + x^3 + ....+ x^n
4// 1 + x^2 + x^3 + ....+ x^n
7// sum of series of
5// sum of series of
6
// 1 + x^2 + x^3 + ....+ x^n
4#include
1
// C++ implementation to find
8#include
3
// C++ implementation to find
8#include
5#include
6// sum of series of
6
// C++ implementation to find
8#include
9 using
0
#include
3
using
2
// C++ implementation to find
3 using
4
// C++ implementation to find
7
// C++ implementation to find
8// C++ implementation to find
3 using
8
// C++ implementation to find
8// C++ implementation to find
3 namespace
1
// C++ implementation to find
8namespace
3
namespace
4namespace
5
namespace
4namespace
7
// C++ implementation to find
8#include
9 std;
0
#include
3
C
std;
2
std;
3
std;
4
std;
5
std;
6
std;
7
// C++ implementation to find
1 // C++ implementation to find
2// C++ implementation to find
3 // C++ implementation to find
4// C++ implementation to find
3 // C++ implementation to find
6
// C++ implementation to find
7
// C++ implementation to find
8// C++ implementation to find
1 // sum of series of
0
// C++ implementation to find
8// Function to find the sum of
9
// C++ implementation to find
8// the series and print N terms
1// the series and print N terms
2// the series and print N terms
3// the series and print N terms
4
// C++ implementation to find
8// the series and print N terms
6
// C++ implementation to find
8// the series and print N terms
8
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
2 // 1 + x^2 + x^3 + ....+ x^n
3
// 1 + x^2 + x^3 + ....+ x^n
4// 1 + x^2 + x^3 + ....+ x^n
5
_______34____91____92____107// C++ implementation to find
08
// 1 + x^2 + x^3 + ....+ x^n
4#include
1
// C++ implementation to find
8#include
3
// C++ implementation to find
8// the series and print N terms
1// the series and print N terms
2#include
6// the series and print N terms
4
// C++ implementation to find
8#include
9 using
0
#include
3
// C++ implementation to find
22
// C++ implementation to find
3 using
4
// C++ implementation to find
7
// C++ implementation to find
8// C++ implementation to find
3 using
8
// C++ implementation to find
8// C++ implementation to find
3 namespace
1
_______18____91____92____135// C++ implementation to find
36
// C++ implementation to find
8#include
9 std;
0
#include
3
Java
// C++ implementation to find
41
// C++ implementation to find
42
// 1 + x^2 + x^3 + ....+ x^n
// C++ implementation to find
44 // C++ implementation to find
45
// C++ implementation to find
8// C++ implementation to find
47
// C++ implementation to find
8// C++ implementation to find
0
// C++ implementation to find
8// C++ implementation to find
51 // C++ implementation to find
1 // C++ implementation to find
2// C++ implementation to find
3 // C++ implementation to find
4// C++ implementation to find
3 // C++ implementation to find
6
// C++ implementation to find
8// C++ implementation to find
7
// 1 + x^2 + x^3 + ....+ x^n
4// C++ implementation to find
1 // C++ implementation to find
62____163// C++ implementation to find
64
// 1 + x^2 + x^3 + ....+ x^n
4// sum of series of
2
_______34____168____93// the series and print N terms
4
// 1 + x^2 + x^3 + ....+ x^n
4// sum of series of
8
// 1 + x^2 + x^3 + ....+ x^n
4// C++ implementation to find
74
// 1 + x^2 + x^3 + ....+ x^n
4// C++ implementation to find
76
// 1 + x^2 + x^3 + ....+ x^n
4// 1 + x^2 + x^3 + ....+ x^n
2 // C++ implementation to find
79____180// C++ implementation to find
81
// C++ implementation to find
82// 1 + x^2 + x^3 + ....+ x^n
5
// C++ implementation to find
82// C++ implementation to find
85
// C++ implementation to find
82// C++ implementation to find
68// sum of series of
5// the series and print N terms
4
// C++ implementation to find
82#include
1
// 1 + x^2 + x^3 + ....+ x^n
4#include
3
// 1 + x^2 + x^3 + ....+ x^n
4// C++ implementation to find
95
// 1 + x^2 + x^3 + ....+ x^n
4#include
9 using
0
// C++ implementation to find
8#include
3
// C++ implementation to find
8// C++ implementation to find
22
// C++ implementation to find
8// sum of series of
04 // C++ implementation to find
51 // sum of series of
06 // sum of series of
07
// C++ implementation to find
8// C++ implementation to find
7
// 1 + x^2 + x^3 + ....+ x^n
4// C++ implementation to find
3 // sum of series of
12____213// sum of series of
6
// 1 + x^2 + x^3 + ....+ x^n
4// C++ implementation to find
3 // sum of series of
17____218// sum of series of
6
// 1 + x^2 + x^3 + ....+ x^n
4____221
________ 182 ________ 135 ________ 136
// C++ implementation to find
8#include
3
#include
3
Python3
// sum of series of
28
// sum of series of
29
// sum of series of
30
// sum of series of
31
// sum of series of
32
// sum of series of
33 // sum of series of
34// sum of series of
35
// C++ implementation to find
8
// C++ implementation to find
8// sum of series of
38// sum of series of
39 // C++ implementation to find
63
// C++ implementation to find
8// sum of series of
42____239 // sum of series of
44
// C++ implementation to find
8// sum of series of
46
// C++ implementation to find
8// sum of series of
48// the series and print N terms
2// C++ implementation to find
80// sum of series of
51// sum of series of
39 // sum of series of
5// sum of series of
54
// C++ implementation to find
8// sum of series of
56
// C++ implementation to find
8// sum of series of
58
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
2 // sum of series of
61// sum of series of
62 // sum of series of
63// the series and print N terms
2// C++ implementation to find
80// sum of series of
66
// 1 + x^2 + x^3 + ....+ x^n
4
// 1 + x^2 + x^3 + ....+ x^n
4// sum of series of
38____239 // sum of series of
38// sum of series of
72 // sum of series of
42
// 1 + x^2 + x^3 + ....+ x^n
4// sum of series of
48______92// sum of series of
77 // sum of series of
78 // sum of series of
79// sum of series of
39 // sum of series of
5// sum of series of
54
// 1 + x^2 + x^3 + ....+ x^n
4// sum of series of
42// sum of series of
39 // sum of series of
42// sum of series of
87 // sum of series of
44
// 1 + x^2 + x^3 + ....+ x^n
4
// C++ implementation to find
8// sum of series of
48// the series and print N terms
2// sum of series of
93// sum of series of
54
// C++ implementation to find
8#include
9 using
0
// sum of series of
98
// sum of series of
44// sum of series of
39 // sum of series of
13
// 1 + x^2 + x^3 + ....+ x^n
02// sum of series of
39 // sum of series of
18
// sum of series of
48// the series and print N terms
2// 1 + x^2 + x^3 + ....+ x^n
07 // sum of series of
78 // sum of series of
34// 1 + x^2 + x^3 + ....+ x^n
10
// 1 + x^2 + x^3 + ....+ x^n
11
C#
// 1 + x^2 + x^3 + ....+ x^n
12
// C++ implementation to find
42
// 1 + x^2 + x^3 + ....+ x^n
using
// 1 + x^2 + x^3 + ....+ x^n
16
// C++ implementation to find
44 // 1 + x^2 + x^3 + ....+ x^n
18
// 1 + x^2 + x^3 + ....+ x^n
19
// C++ implementation to find
0
// C++ implementation to find
51 // C++ implementation to find
1 // C++ implementation to find
2// C++ implementation to find
3 // C++ implementation to find
4// C++ implementation to find
3 // C++ implementation to find
6
// C++ implementation to find
7
// C++ implementation to find
8// C++ implementation to find
1 // sum of series of
0
// C++ implementation to find
8// sum of series of
2
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
35// the series and print N terms
3// the series and print N terms
4
// C++ implementation to find
8// sum of series of
8
// C++ implementation to find
8// C++ implementation to find
74
// C++ implementation to find
8// C++ implementation to find
76
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
2 // 1 + x^2 + x^3 + ....+ x^n
46
// C++ implementation to find
8// C++ implementation to find
7
// 1 + x^2 + x^3 + ....+ x^n
4// 1 + x^2 + x^3 + ....+ x^n
5
// 1 + x^2 + x^3 + ....+ x^n
4// 1 + x^2 + x^3 + ....+ x^n
52
// 1 + x^2 + x^3 + ....+ x^n
4// 1 + x^2 + x^3 + ....+ x^n
35____25// the series and print N terms
4
// 1 + x^2 + x^3 + ....+ x^n
4#include
1
// C++ implementation to find
8#include
3
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
62
// C++ implementation to find
8#include
9 using
0
#include
3
// C++ implementation to find
22
// sum of series of
04 // C++ implementation to find
51 // sum of series of
06 // 1 + x^2 + x^3 + ....+ x^n
71
// C++ implementation to find
7
// C++ implementation to find
8// C++ implementation to find
3 using
8
// C++ implementation to find
8// C++ implementation to find
3 namespace
1
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
35// 1 + x^2 + x^3 + ....+ x^n
81// C++ implementation to find
36
#include
3
#include
3
// 1 + x^2 + x^3 + ....+ x^n
85
Javascript
// 1 + x^2 + x^3 + ....+ x^n
86
// 1 + x^2 + x^3 + ....+ x^n
87
// sum of series of
// 1 + x^2 + x^3 + ....+ x^n
________số 8
// the series and print N terms
// C++ implementation to find
0
// 1 + x^2 + x^3 + ....+ x^n
93 // 1 + x^2 + x^3 + ....+ x^n
94
// C++ implementation to find
7
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
97
// C++ implementation to find
8// sum of series of
2
// C++ implementation to find
8#include
01____25// the series and print N terms
4
// C++ implementation to find
8// sum of series of
8
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
0
// C++ implementation to find
8// 1 + x^2 + x^3 + ....+ x^n
2 // 1 + x^2 + x^3 + ....+ x^n
3
// 1 + x^2 + x^3 + ....+ x^n
4// 1 + x^2 + x^3 + ....+ x^n
5
_______34____414____25____94
// 1 + x^2 + x^3 + ....+ x^n
4#include
1
// C++ implementation to find
8#include
3
// C++ implementation to find
8#include
22____423// the series and print N terms
4
// C++ implementation to find
8#include
9 using
0
#include
3
using
2
// C++ implementation to find
8#include
31
// C++ implementation to find
8#include
33
// C++ implementation to find
8#include
35
#include
36
#include
37
đầu ra.
1 2.0 4.0 8.0 16.0 31.00
Thời gian phức tạp. Trên]
Không gian phụ trợ. O[1], vì không có khoảng trống thừa nào được sử dụng
Ghi chú cá nhân của tôi arrow_drop_up
Tiết kiệm