umdrehen funktion muss noch richtig implementiert werden
This commit is contained in:
parent
5d9af7d957
commit
61a8c98dcb
55
Quersumme.c
Normal file
55
Quersumme.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int umdrehen(int zahl) {
|
||||||
|
int result;
|
||||||
|
int temp;
|
||||||
|
if(zahl<10){
|
||||||
|
return zahl;
|
||||||
|
}
|
||||||
|
temp = zahl%10;
|
||||||
|
result = temp + 10 * umdrehen(zahl / 10);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int quersumme(int zahl) {
|
||||||
|
int result;
|
||||||
|
int temp;
|
||||||
|
if(zahl<10) {
|
||||||
|
return zahl;
|
||||||
|
}
|
||||||
|
temp = zahl%10;
|
||||||
|
result = temp + quersumme(zahl / 10);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int input() {
|
||||||
|
|
||||||
|
int eingabe;
|
||||||
|
int ok = 0;
|
||||||
|
char c;
|
||||||
|
printf("Gib eine Zahl ein: ");
|
||||||
|
ok = scanf("%d%c", &eingabe, &c);
|
||||||
|
|
||||||
|
while (ok != 2 || c != '\n') {
|
||||||
|
ok = scanf("%d%c", &eingabe, &c);
|
||||||
|
while ((c = getchar()) != '\n' && c != EOF) {}
|
||||||
|
printf("Ungueltige Eingabe!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return eingabe;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int eingabe, ergebnisQuer, ergebnisGedreht;
|
||||||
|
|
||||||
|
eingabe = input();
|
||||||
|
ergebnisQuer = quersumme(eingabe);
|
||||||
|
ergebnisGedreht = umdrehen(eingabe);
|
||||||
|
printf("----Quersumme: %d\n", ergebnisQuer);
|
||||||
|
printf ("----Umgedreht: %d\n", ergebnisGedreht);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user