Latihan Kode Program C++: Penjumlahan Deret Angka
Latihan Kode Program C++: Penjumlahan Deret Angka
!"#$ $ #
<+&76/2"%"&'F+-+#'?&.("
Latihan Kode
Program C++:
Penjumlahan Deret
Angka
@S'^5#'@@ '_ '?&*-+ '_ 'U6#)-$"2'011 '_ 'J)
0)//+
!"#$%"&'()*+',-).-"/'011'("2$'$&$'"("&
/+/3"%"4'5"-"'/+/36"#',+&76/2"%"&
*+-+#'"&.("8'9"#+-$'$&$'6/6/&:"'*$,"("$
6('/+&.67$',+/"%"/"&'4+,6#"-
),+-"#)-'"-$#/"#$("'4+-#"',+-62"&."&8
?."-'2+3$%'/+&"&#"&.>'36"#'*"2"/'@'A+-4$
,+-62"&."&B'!"#$%&'(&')*+#'*"&
!"#$%&'(&'),-.%"8
;+-$(6#'5)&#)%'#"/,$2"&'"(%$-':"&.
*$$&.$&("&'C=D'B
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +
55
;+-$(6#'5)&#)%'#"/,$2"&'"(%$-':"&.
*$$&.$&("&'C@D'B
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +
120
?&.("'$&,6#'3$4"'*$4$/,"&'(+'*"2"/'4"#6
A"-$"3+2'$&#+.+->'(+/6*$"&'36"#
,+-62"&."&'6('/+&"/,$2("&'*+-+#8'F$
*"2"/',+-62"&."&'$&$>'#"/,6&.'"&.("
*+-+#'*"&'#"/,$2("&'%"4$2&:"'4+#+2"%
,+-62"&."&'4+2+4"$8
E$2"%("&'"&*"'5)3"'4+3+&#"-'6(
/+/36"#'()*+',-).-"/'*"-$'4)"2'*$'"#"48
1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 cout << "## Program C++ Pen
7 dl;
8 cout << "===================
9 dl;
10 cout << endl;
11
12 int i, n, total;
13
14 cout << "Jumlah deret yang d
15 cin >> n;
16 cout << endl;
17
18 total = 1;
19 cout << 1;
20 for (i = 2; i <= n; i++) {
21 cout << " + " << i;
22 total = total + i;
23 }
24 cout << " = " << total;
25
26 cout << endl;
return 0;
}
H"4$2'()*+',-).-"/B
<-).-"/'/+/$&#"'='*"#"'$&,6#"&'3+-6,"
76/2"%'*+-+#',"*"'3"-$4'=I8'J$2"$'$&$
*$4$/,"&'(+'*"2"/'A"-$"3+2' n '*+&."&
,+-$&#"%' cin >> n 8
<-)4+4'/+&"/,$2("&'*+-+#'*$2"(6("&')2+%
,+-62"&."&'G)-'*$'3"-$4'=PQ@=8'<+-62"&."&
*$/62"$'*"-$' i = 2 '("-+&"'"&.("'='46*"%
($#"'#"/,$2("&'4+3+26/&:"8'<+-$&#"%' cout
<< " + " << i '"("&'/+&"/,$2("&'#+(4
R + 2 + 3 + 4 + 5 + ... + n R8
<-)4+4',+&76/2"%"&'*+-+#'*$2"(6("&
*+&."&',+-$&#"%' total = total + i '*$
3"-$4'@S8'K)*+'$&$'"("&'/+&"/3"%'$4$
A"-$"3+2' total '*+&."&' i '*"&
/+&:$/,"&&:"'(+/3"2$'(+'*"2"/'A"-$"3+2
total 8'T&$'#+-64'*$2"(6("&'4"/,"$
,+-62"&."&'4+2+4"$8
U+-"(%$->'#$&.."2'#"/,$2("&'$4$'A"-$"3+2
total '*+&."&',+-$&#"%' cout '*$'3"-$4'@@8
U$*"('26,"'#"&*"'4"/"'*+&."&'O'V'O'"."-
#"/,$2"&&:"',"4'*+&."&'#)#"2'*+-+#8
F+/$($"&'()*+',-).-"/',+&76/2"%"&
*+-+#'"&.("'*+&."&',+-62"&."&'G)-8
Rp 900,000
Omah Loji @ Mega Kuningan
1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 cout << "## Program C++ Pen
7 dl;
8 cout << "===================
9 dl;
10 cout << endl;
11
12 int i, n, total;
13
14 cout << "Jumlah deret yang d
15 cin >> n;
16 cout << endl;
17
18 cout << 1;
19 total = 1;
20 i = 2;
21 while (i <= n) {
22 cout << " + " << i;
23 total = total + i;
24 i++;
25 }
26 cout << " = " << total;
27
28 cout << endl;
return 0;
}
J$2"$'"X"2'A"-$"3+2'$'*$#62$4',"*"'3"-$4'=P>
#+,"#'4+3+26/'/"46('(+'*"2"/
,+-62"&."&'X%$2+8
K)&*$4$':"&.'%"-64'*$,+&6%$'6(
,+-62"&."&'X%$2+'"*"2"%' i <= n >':"&.
3+-"-#$',+-62"&."&'"("&'#+-64'3+-7"2"&
4+2"/"'&$2"$'A"-$"3+2' i '/"4$%'(6-"&.'*"-$
A"-$"3+2' n 8
F"2"/'4+#$",',+-62"&."&>'#+#",'7"2"&("&
,+-$&#"%':"&.'4"/"'4+,+-#$'*$',+-62"&."&
G)->':"(&$'#"/,$2("&'"&.("'*+-+#'*+&."&
,+-$&#"%' cout << " + " << i >'*"&
%$#6&.'#)#"2'"&.("'*+-+#'*+&."&',+-$&#"%
total = total + i 8
U$*"('26,">',+-26',+-$&#"%'$&5-+/+&#' i++
6('/+&"$(("&'&$2"$'A"-$"3+2'$'*"2"/
4+#$",'$#+-"4$8'<+-62"&."&'X%$2+'56(6,
-"X"&'#+-7"*$'#%&%#!'()**+'7$("'($#"'26,"
/+/36"#',+-$&#"%'$&5-+/+
T#62"%'()*+',-).-"/',+&76/2"%"&'*+-+#
"&.("'6('A+-4$',+-62"&."&'X%$2+8
F+/$($"&'()*+',-).-"/',+&76/2"%"&
*+-+#'"&.("'/+&..6&"("&'3"%"4"
,+/-).-"/"&'0118'E+/)."'#6#)-$"2'$&$
3$4"'3+-/"&G""#8
ADD COMMENT
0)//+&#'U+Z#[
J"/+[
\/"$2[
]+34$#+
' J)#$G:'/+')G'G)22)XQ6,'5)//+'3:
+/"$28
' J)#$G:'/+')G'&+X',)4#4'3:'+/"$28
2345)6377895
eBook Programming
Duniailkom
0"-"',+/+4"&"&'+;))('`';6(6'F6&$"$2()/
U6#)-$"2'U+-3"-6'F6&$"$2()/
U6#)-$"2'HU9!
U6#)-$"2'0EE
U6#)-$"2'<H<
U6#)-$"2'9:Eb!
U6#)-$"2'a"A"E5-$,#
U6#)-$"2';"%"4"'0
U6#)-$"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<+&.+-#$"&'<+-$&#"%';e\?K'011
IL8'<+&.+-#$"&'<+-$&#"%'0^JUTJW\
011
IN8'0"-"'9+/36"#'g6&5#$)&
IP8'<+&.+-#$"&'<"-"/+#+-'`
?-.6/+&
Ic8'g6&.4$'<+-$&#"%'e+#6-&
fS8'<+&.+-#$"&'F+G"62#'<"-"/+#+-
f=8'g6&5#$)&'^A+-2)"*$&.
E)"2'!"#$%"&'?2.)-$#/"';"%"4"'011
U6#)-$"2'^^<'011
Berlangganan Artikel
Duniailkom
F","#("&',+/3+-$#"%6"&'6('4+#$",'"-#$(+2
*"&'#6#)-$"2'#+-3"-6'F6&$"$2()/
\/"$2'?**-+44
E6345-$3+
a)$&'=L>=N@')#%+-'46345-$3+-4
Duniailkom
!"#$%
!&''
!("(
!$)'*%
!+,-,'&./(#
!01.2(.3''
!03415%/53
!(,'&,%
F6&$"$2()/'"*"2"%'4$#64'3+2"7"-',-).-"//$&.'*"&'$2/6
()/,6#+-8'F$%"-",("&'*6&$"$2()/85)/'*","#'/+&7"*$
/+*$"'3+2"7"-'*"&'4"2$&.'3+-3".$'#+&#"&.',-).-"//$&.>
%"-*X"-+>'/"6,6&'#+)-$'4+,6#"-'*6&$"'()/,6#+-8'T(6#$
"(6&'/+*$"'4)5$"2'*6&$"$2()/'6('6,*"#+'#+-3"-6B
g"5+3))('F6&$"$2()/>'UX$##+-'F6&$"$2()/
#
___ Pelajari Lebih Lanjut
Learn More
0),:-$.%#'h'@S@I'F6&$"$2()/'_'H)4#$&.'-+()/+&*"4$
F6&$"$2()/
!"#$%&'(&)%" _ *#+,-./&*'0+./ _
Skip Ad
1+%.0-+$"# _ Iklan : (0:14)
-2')!&)% _ .'3!-.!&)%
!"