Systemnahe Programmierung in C: Parameterübergabe |
1int
2sum1 (int n)
3{
4 if (n <= 0)
5 return 0;
6 else
7 return n + sum1 (n - 1);
8}
|
1int
2sum2 (int n)
3{
4 return
5 n <= 0
6 ? 0
7 : n + sum2 (n - 1);
8}
|
1int
2sum3 (int n)
3{
4 return n * (n + 1) / 2;
5}
|
1#include <stdio.h>
2
3#include "sum1.c"
4#include "sum2.c"
5#include "sum3.c"
6
7int
8main (void)
9{
10 int i = 25;
11
12 printf ("Die Summe der ersten %d %s %d oder %d oder %d\n",
13 i,
14 "Zahlen ist",
15 sum1 (i),
16 sum2 (i),
17 sum3 (i));
18
19 return 0;
20}
|
1void
2swap (int x, int y)
3{
4 int tmp;
5
6 tmp = x;
7 x = y;
8 y = tmp;
9}
10
11int a, b;
12
13swap (a, b);
|
1void
2swap (int *x, int *y)
3{
4 int tmp;
5 tmp = *x;
6 *x = *y;
7 *y = tmp;
8}
9
10int a, b;
11
12swap (&a, &b);
|
1void
2swap (x, y)
3 int *x;
4 int *y;
5{
6 int tmp;
7 tmp = *x;
8 *x = *y;
9 *y = tmp;
10}
|
|
Letzte Änderung: 11.01.2007 | © Prof. Dr. Uwe Schmidt |