Skip to content

Instantly share code, notes, and snippets.

@d630
Last active May 24, 2018 16:29
Show Gist options
  • Save d630/17b091ab60e315a86028dcae18127322 to your computer and use it in GitHub Desktop.
Save d630/17b091ab60e315a86028dcae18127322 to your computer and use it in GitHub Desktop.
Übungen C
#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 :
#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 :
#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 :
#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 :
@1el
Copy link

1el commented May 23, 2018

@d630
Copy link
Author

d630 commented May 24, 2018

von wegen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment