Created
April 26, 2010 10:23
-
-
Save moschlar/379176 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. | |
// Michael Neumann und Moritz Schlarb | |
2. | |
// | |
3. | |
// Programmiersprachen, SoSe 2010 | |
4. | |
// Übung zur Vorlesung vom 19.04.2010 | |
5. | |
// | |
6. | |
// Aufgabe 2 | |
7. | |
8. | |
#include <stdio.h> | |
9. | |
#include <stdlib.h> | |
10. | |
11. | |
void vertausche1(int x, int y) | |
12. | |
{ | |
13. | |
int h; | |
14. | |
h = x; | |
15. | |
x = y; | |
16. | |
y = h; | |
17. | |
} | |
18. | |
19. | |
void vertausche2(int *x, int y) | |
20. | |
{ | |
21. | |
int h; | |
22. | |
h = *x; | |
23. | |
*x = y; | |
24. | |
y = h; | |
25. | |
} | |
26. | |
27. | |
void vertausche3(int *x, int *y) | |
28. | |
{ | |
29. | |
int h; | |
30. | |
h = *x; | |
31. | |
*x = *y; | |
32. | |
*y = h; | |
33. | |
} | |
34. | |
35. | |
int main(void) | |
36. | |
{ | |
37. | |
int a = 2; | |
38. | |
int b = 3; | |
39. | |
printf("Anfangswerte:\n"); | |
40. | |
printf("a = %d b = %d\n\n", a, b); | |
41. | |
42. | |
printf("vertausche1(int x, int y)\n"); | |
43. | |
vertausche1(a,b); | |
44. | |
printf("a = %d b = %d\n\n", a, b); | |
45. | |
46. | |
a = 2; | |
47. | |
b = 3; | |
48. | |
49. | |
printf("vertausche2(int *x, int y)\n"); | |
50. | |
vertausche2(&a,b); | |
51. | |
printf("a = %d b = %d\n\n", a, b); | |
52. | |
53. | |
a = 2; | |
54. | |
b = 3; | |
55. | |
56. | |
printf("vertausche3(int *x, int *y)\n"); | |
57. | |
vertausche3(&a,&b); | |
58. | |
printf("a = %d b = %d\n\n", a, b); | |
59. | |
60. | |
return 0; | |
61. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment