%( ,( - ( #
+
"
) *
#$ %& #$ '
.
#$ (
#$ ( %
!
!
if/
!
if
o
o
if !
if-else !
#
0
if/
!
#1
!
bool
if/else !
if/!
2
if
if
2
&
%
3
else
,
int a;
std::cin >> a;
if (a % 2 == 0)
std::cout << "even";
#1
%#0
,#0
if/else !
if
8
67 #
%
"
1
5
,
"
1
5
else
o
int a;
std::cin >> a;
if (a % 2 == 0)
std::cout << "even";
else
std::cout << “odd";
o
o
for/!
while/!
do/!
bool
if/4
else/4
%(,(-(
+
// Program: sum_n.C
// Compute the sum of the first n natural numbers.
for/
!
/
for
<;
#include <iostream>
int main()
{
// input
std::cout << "Compute the sum 1+...+n for n =? ";
unsigned int n;
std::cin >> n;
/
// computation of sum_{i=1}^n i
unsigned int s = 0;
for (unsigned int i = 1; i <= n; ++i) s += i;
0
}
for
<;
#
for (unsigned int i = 1; i <= n; ++i)
s += i;
1
&:
!
!
&
1
for/
!
/
91
#1
#
#
for/
!
;
// output
std::cout << "1+...+" << n << " = " << s << ".\n";
return 0;
for/
!
#!
91
/
for
!
1
<;
=7 bool#
for (unsigned int i = 1; i <= n; ++i)
s += i;
for/!
for/!
/
for
!
1
<;
=7 unsigned int#
!
for (unsigned int i = 1; i <= n; ++i)
1
<;
3
!
3
;
# for/!
for/!
#+
for (unsigned int i = 1; i <= n; ++i)
s += i;
/
#8
#
s += i; // Rumpf
#
/
for
1
<;
for (unsigned int i = 1; i <= n; ++i)
s += i;
for/!
/
for
# n == 2
s == 0
i == 1 i <= 2 ?
3
3
3
3
for/!
#+
#+
for/!
for (unsigned int i = 1; i <= n; ++i)
s += i;
for (unsigned int i = 1; i <= n; ++i)
s += i;
!
!
# n == 2
s == 0
i == 1
for/!
#+
for (unsigned int i = 1; i <= n; ++i)
s += i;
!
# n == 2
s == 0
s == 1
s == 3
s == 3
# n == 2
s == 0
s == 1
9 1
B
>
i == 1
%???/%@AA
/6
!
C
#
4
%
i == 1
i == 2
i == 3
>
%''5
B
3
9
1
9
6
D
>
%???/%@AA
>
#
4
% ( ,( E( 3
3
3( F@ ( FF( %''
GC
% ( ,( E( 3
3
3( F@ ( FF( %''(
%''( FF(F@ ( 3
3
3( E ( ,( % $
%'%''
!
#=
for/!
for (unsigned int i = 1; i <= n; ++i)
s += i;
G
#
;
C
1
&
8
#=
2
#A'A'
"
2
"
#
for ( ;
6
; ) ;
#
for ( ;
2
6
;
; ) ;
1
" 1
"
"
#
for ( ;
#
; ) ;
for (e; v;e)r;
: /
!
: /
!
-
G
+
C
1 H((
H((
1 1
"
1
&
.
&
&
J
,&
-&/
%K
=
3
unsigned int d;
for (d = 2; n % d != 0; ++d);
"
3
3
#
I,
#
1
"
.
1
0
: /
!
5
+
#
+
I,
1
I,
&
J
,&
-&/
%K
=
3
unsigned int d;
for (d = 2; n % d != 0; ++d);
for/
!
:
+
#
#
&
J
,&
-&/
%K
1
=
unsigned int d;
for (d = 2; n % d != 0; ++d);
) 3
$ 3
+ D1
// Program: prime.C
// Test if a given natural number is prime.
!
#include <iostream>
int main ()
{
// Input
unsigned int n;
std::cout << "Test if n>1 is prime for n =? ";
std::cin >> n;
// Computation: test possible divisors d
unsigned int d;
for (d = 2; n % d != 0; ++d);
// Output
if (d < n)
// d is a divisor of n in {2,...,n-1}
std::cout << n << " = " << d << " * " << n / d << ".\n";
else
// no proper divisor found
std::cout << n << " is prime.\n";
return 0;
}
3
!
J
+
o
%
,-
:K
#
int main(){…}
+
10
/ 1
+D 1
1
!
91
!
J
+
%
,-
:K
+
#
o
int main(){…}
o
for (unsigned int i = 1; i <= n; ++i) {
+
1
s += i;
std::cout <<
+
partial sum is
<< s <<
1
int main ()
{
1
{
int i = 2;
}
std::cout << i; // Fehler: undeklarierter Name
return 0;
}
\n
$ +
1
91
0
3
3
3
4
1
3
91
3
3
3
#
+D 1 #
int main()
{
for (unsigned int i = 0; i < 10; ++i) s += i;
std::cout << i; // Fehler: undeklarierter Name
return 0;
}
&
+
1
1
{
int i = 2;
}
#
9 1
0
333
9 1
333
9 1
#
333
&
1
9 1
1
#
&
9 1
0
#{int
1
>
1
333
9 1
"
333
#
for (int i = 0; i < 5; ++i)
// outputs 0, 1, 2, 3, 4
std::cout << i;
1
B
}
for (unsigned int i = 0; i < 10; ++i) s += i;
#include <iostream>
int main()
{
int i = 2;
3 3
main()
1
333
#
int main()
{
int i = 2;
return 0;
}
&
int i = 2;
return 0;
int i = 2;
}
1
+ 1
>
{
#
&
for (unsigned int i = 0; i < 10; ++i) s += i;
1
333
9 1
#
+ 1
333
0
>
333
// outputs 2
std::cout << i;
/
return 0;
}
5
>
1
333
#include <iostream>
>
1
333
91
int main()
{
int i = 2;
91
:
>
1
91
3
#
>
for (int i = 0; i < 5; ++i)
// outputs 0, 1, 2, 3, 4
std::cout << i;
1
// outputs 2
std::cout << i;
1
91
>
return 0;
/
#include <iostream>
int main()
{
int i = 2;
for (int i = 0; i < 5; ++i)
// outputs 0, 1, 2, 3, 4
std::cout << i;
/
// outputs 2
std::cout << i;
:
}
!
333
return 0;
}
!
61
.
"
91
&3 3
L!
38
"
0
&!
1
int i = 5;
for (int j = 0; j < 5; ++j) {
std::cout << ++i; // outputs 6, 7, 8, 9, 10
int k = 2;
std::cout << --k; // outputs 1, 1, 1, 1, 1
}
while/!
while/!
while (
)
#
0
while (
!
CM
while/!
#1
while/!
)
for ( ;
bool
#
1
while/!
while
for/!
; )
#
*
;
C
4C
3
#8
3
for (unsigned int i = 1; i <= n; ++i)
3
# while/!
s += i;
3
&
1
while
while/!
H
/
'
while/!
#+
4
H
$
/
'
&
/%L,
&
/%( %
while/!
// Input
std::cout << "Compute the Collatz sequence for n =? ";
unsigned int n;
std::cin >> n;
// Iteration
while (n > 1) {
// stop if 1 is reached
if (n % 2 == 0)
// n is even
n = n / 2;
else
// n is odd
n = 3 * n + 1;
std::cout << n << " ";
}
&I%
E
H
#+
/%
$
/%
A&%N&@&O&,&%&O&,&%&-
#
$
&
/%L,
&I%
E
4
/%
$
$ A#
#
#+
&
/%( %
/
9 H
&
/%
4
%
3
/
$ ,?#
@,&O%&%,O&N,&E%&FO&O?&%O,&?%&,%O&%'?&E,,&
%N%&O@O&,O,&%,%&ENO&%@,&F%&,?O&%E?&O%,&
,'N&%'E&E%'&%AA&ONN&,EE&?''&EA'&%?A&A,N&
,NE&?F'&EFA&%%@N&AFE&%?@'&@F'&OOA&%EEN&
NN@&EEO&%N?&A',&,A%&?AO&E??&%%E,&ANN&,@E&
@A'&O,A&%,?N&NE@&E%F&FA@&O?F&%OE@&?%F&
,%A@&%'?F&E,E@&%N%F&O@A@&,O,F&?,@@&ENOO&
%@,,&F%%&,?EO&%EN?&O%',&,'A%&N%AO&E'??&
F,E,&ON%N&,E'@&%%AO&A??&%?E,&@NN&OEE&%E''&
NA'&E,A&F?N&O@@&,OO&%,,&N%&%@O&F,&ON&,E&
?'&EA&%'N&AE&%N'&@'&O'&,'&%'&A&%N&@&O&,&%
9
H
do/!
/
"
%
B
.
do
*
&
5
&
while/!
H
/
"
+
do/!
;
while
1
<
#
do/!
#1
0
;
5
bool
3
3
3
for&while
#
do/!
do
!
1
do
while
;
<
while
;
8
CM
<
#
3
for (bool firsttime = true; firsttime ||
;
; firsttime = false)
;
3
#
#do/!
3
do/!
=
#+
#
4
4
'
!
o
int a;
// next input value
int s = 0; // sum of values so far
do {
std::cout << "next number =? ";
std::cin >> a;
s += a;
std::cout << "sum = " << s << "\n";
} while (a != 0);
#
if/
if-else/!
8
o
o
o
#
for/!
while/!
do/!
+ D1
>
1
91
break/!
while
do
1
break;
&
8
#
3
&
1
&
B
1
D
break/!
=
#
break/!
#+
4
'
=
int a;
// next input value
int s = 0; // sum of values so far
do {
std::cout << "next number =? ";
std::cin >> a;
#
#+
1
!
'
s += a; // irrelevant in final iteration
std::cout << "sum = " << s << "\n";
} while (a != 0);
int a;
// next input value
int s = 0; // sum of values so far
do {
std::cout << "next number =? ";
std::cin >> a;
if (a == 0) break; // termination in the middle
s += a;
std::cout << "sum = " << s << "\n";
} while (true);
break/!
break/!
=
# CM
#+
#
int a;
// next input value
int s = 0; // sum of values so far
for (;;) { // forever...
std::cout << "next number =? ";
std::cin >> a;
if (a == 0) break; // Abbruch in der Mitte
s += a;
std::cout << "sum = " << s << "\n";
}
=
#
C
#+
+
1#
1
int a = 1; // next input value
int s = 0; // sum of values so far
for (; a != 0;) {
std::cout << "next number =? ";
std::cin >> a;
if (a == 0) {
s += a;
std::cout << "sum = " << s << "\n";
}
}
continue/!
continue/!
=
"
continue;
0
PM
8
while 1
G
for
/
<;
while/!
CM
5
#
8
for
for/!
>
#
do 1
D
:
"
#
#
for (;;) {
std::cout << "next number =? ";
std::cin >> a;
if (a < 0) continue; //skip next 3 lines if a<0
if (a == 0) break;
s += a;
std::cout << "sum = " << s << "\n";
}
0
8
8
2
o while
for
#+
5
/
while
!
11
1
"
#
;
{
<
}
&
continue;
C5
!
8
4
!
8
#6
1 & C
!
4
!
!
38
"
H
1
4
3
!
8
2
4
!
&
J
'&
3
3
3
&
%''K
#
4
4
1
1
#
for (unsigned int i = 0; i < 100; ++i)
if (i % 2 != 0) std::cout << i << "\n";
J
'&
3
3
3
&
%''K
#
#
for (unsigned int i = 0; i < 100; ++i)
{
if (i % 2 == 0) continue;
std::cout << i << "\n";
}
!
8
#+
!
#+
#+
!
2
4
!
J
'&
3
3
3
&
%''K
#
&
#
for (unsigned int i = 1; i < 100; i += 2)
std::cout << i << "\n";
9
8
5
© Copyright 2026 Paperzz