Last active
May 24, 2018 16:29
-
-
Save d630/17b091ab60e315a86028dcae18127322 to your computer and use it in GitHub Desktop.
Übungen C
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
#include <stdio.h> | |
int main(void) | |
{ | |
int s; | |
int g = 0; | |
puts("Anzahl Schrauben? "); | |
scanf("%d", &s); | |
g += s*7; | |
puts("Anzahl Mütter? "); | |
scanf("%d", &s); | |
g += s*4; | |
puts("Anzahl Unterlegscheiben? "); | |
scanf("%d", &s); | |
g += s*2; | |
printf("Gesamt: %d\n", g); | |
return 0; | |
} | |
// vim: set ts=8 sw=8 tw=0 noet : |
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
#include <stdio.h> | |
int main(void) | |
{ | |
int r; | |
int z = 0; | |
int i; | |
do { | |
r = 0; | |
z++; | |
for (i = 1; i <= 10; i++) | |
r += z % i; | |
} while (r != 0); | |
printf("Zahl ist %d\n", z); | |
return 0; | |
} | |
// vim: set ts=8 sw=8 tw=0 noet : |
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
#include <stdio.h> | |
int main(void) | |
{ | |
unsigned int s; | |
int p = 0; | |
printf("digit: "); | |
scanf("%d", &s); | |
while (s != 0) { | |
p++; | |
if (s & 1) | |
printf("%d. Bit gesetzt\n", p); | |
else | |
printf("%d. Bit nicht gesetzt\n", p); | |
s >>= 1; | |
} | |
return 0; | |
} | |
// vim: set ts=8 sw=8 tw=0 noet : |
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
#include <stdio.h> | |
int main(void) | |
{ | |
int g; | |
int array[] = { | |
64, | |
32, | |
16, | |
8, | |
4, | |
2, | |
1 | |
}; | |
printf("Gewicht: "); | |
scanf("%d", &g); | |
for (int i = 0; i < (sizeof(array)/sizeof(array[0])); i++) { | |
printf("%d x %dkg\n", g / array[i], array[i]); | |
g %= array[i]; | |
} | |
return 0; | |
} | |
// vim: set ts=8 sw=8 tw=0 noet : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Andere nicht so elegante Lösung: https://gist.github.com/1el/be343900d6d20eacef58af7c9ecac84d#file-aufgabe3-c :)