Commit 5aab2530 authored by Alija Sabic's avatar Alija Sabic
Browse files

Update and add snippets from unit. Correct flow charts

parent ab1cf1c2
......@@ -12,7 +12,8 @@
#include <stdlib.h>
// function prototype a.k.a. declaration
double calculateArea(double a, double b);
double calculateArea(double length, double width);
double calculatePerimeter(double length, double width);
int main(void) {
double x = 10;
......@@ -20,8 +21,10 @@ int main(void) {
// function call
double area = calculateArea(x, y);
double perimeter = calculatePerimeter(x, y);
printf("Die Fläche beträgt: %.2f m²\n", area);
printf("Der Umfang beträgt: %.2f m.\n", perimeter);
return EXIT_SUCCESS;
}
......
......@@ -11,10 +11,18 @@
#include <stdio.h>
#include <stdlib.h>
#define MIN 0
#define MAX 30
#define MIN (0)
#define MAX (30)
int main(void) {
for (int i = MIN; i <= MAX/2; i++) printf("%d ",i*2);
// One-line solution
// for (int i = MIN; i <= (MAX/2); i++) printf("%d ",i*2);
// Better, more-readable solution
for (int i = MIN; i <= (MAX/2); i++) {
printf("%d ", i*2);
}
return EXIT_SUCCESS;
}
This diff is collapsed.
......@@ -18,6 +18,7 @@ int main(void) {
int a = 12;
int b = 44;
printf("ggT(%d,%d) = %d\n", a, b, gcd(a, b));
printf("ggT(%d,%d) = %d\n", a, b, gcd2(a, b));
return EXIT_SUCCESS;
......@@ -27,7 +28,7 @@ int gcd(int a, int b) {
int result = 0;
if ( a == 0) {
result = b;
result = abs(b);
}
else {
while (b != 0) {
......@@ -38,22 +39,22 @@ int gcd(int a, int b) {
b = b - a;
}
}
result = a;
result = abs(a);
}
return result;
}
int gcd2(int a, int b) {
int result = 0;
int helper = 0;
if ( a == 0 ) return abs(b);
if ( b == 0 ) return abs(a);
do
{
result = a % b;
helper = a % b;
a = b;
b = result;
b = helper;
}
while(b != 0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment