This commit is contained in:
Bora Zuenbuelkoek 2025-05-05 15:53:56 +02:00
parent 8d2fe6fc9c
commit ebc9ac45db
6 changed files with 93 additions and 1 deletions

View File

@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="22.5.2" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" folderName="New Folder" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Info2P5" TARGET_NAME="22.5.c" CONFIG_NAME="22.5.2">
<configuration default="false" name="22.5.2" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" folderName="New Folder" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Info2P5" TARGET_NAME="22.5.2" CONFIG_NAME="22.5.2">
<option name="sourceFile" value="C:\Users\z004tv1b\CLionProjects\Info2P5\22.5.c" />
<method v="2">
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />

BIN
a.exe

Binary file not shown.

35
adturing.c Normal file
View File

@ -0,0 +1,35 @@
#include <string.h>
void dual_addiere_eins(const char *input, char *output, int maxlen) {
int len = strlen(input);
int carry = 1;
int i, j;
// Das Ergebnis wird rückwärts in ein temporäres Array geschrieben
char temp[maxlen];
temp[maxlen-1] = '\0'; // String-Ende
for (i = len - 1, j = maxlen - 2; i >= 0 && j >= 0; --i, --j) {
if (input[i] == '1') {
temp[j] = carry ? '0' : '1';
if (carry) carry = 1; // bleibt 1
} else if (input[i] == '0') {
temp[j] = carry ? '1' : '0';
carry = 0;
} else {
output[0] = '\0'; // Fehlerfall
return;
}
}
// Falls noch Übertrag übrig ist
if (carry && j >= 0) {
temp[j--] = '1';
}
// Rest auffüllen
while (j >= 0) temp[j--] = '0';
// Jetzt führende Nullen entfernen
int start = 0;
while (temp[start] == '0' && temp[start+1] != '\0') ++start;
strcpy(output, temp + start);
}

16
bildschi.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
void dualzahl_einlesen(char *buffer, int maxlen) {
printf("Geben Sie eine Dualzahl ein: ");
if (fgets(buffer, maxlen, stdin) == NULL) {
buffer[0] = '\0';
return;
}
// Zeilenumbruch entfernen
for (int i = 0; buffer[i]; ++i)
if (buffer[i] == '\n') buffer[i] = '\0';
}
void dualzahl_ausgeben(const char *buffer) {
printf("Ergebnis: %s\n", buffer);
}

34
dualaddi.c Normal file
View File

@ -0,0 +1,34 @@
#include <stdio.h>
#include <string.h>
// Funktionsprototypen
void fehlerausgabe(const char *msg);
void dualzahl_einlesen(char *buffer, int maxlen);
void dualzahl_ausgeben(const char *buffer);
void dual_addiere_eins(const char *input, char *output, int maxlen);
#define MAXLEN 65
int main() {
char input[MAXLEN];
char output[MAXLEN];
dualzahl_einlesen(input, MAXLEN);
// Eingabe prüfen
for (int i = 0; input[i]; ++i) {
if (input[i] != '0' && input[i] != '1') {
fehlerausgabe("Nur 0 und 1 erlaubt!");
}
}
dual_addiere_eins(input, output, MAXLEN);
if (output[0] == '\0') {
fehlerausgabe("Fehler bei der Addition!");
}
dualzahl_ausgeben(output);
return 0;
}

7
fehler.c Normal file
View File

@ -0,0 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
void fehlerausgabe(const char *msg) {
fprintf(stderr, "Fehler: %s\n", msg);
exit(1);
}