Advertisement
DarioCas

C Logic Gate Calculator

May 25th, 2020
1,319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. // Variabeln
  6.  
  7. char verknuepfungInput;
  8. int input1;
  9. int input2;
  10. int resultat;
  11.  
  12. int main()
  13. {
  14.     printf("AND-Verknuepfung: \t&");
  15.     printf("\nOR-Verknuepfung: \t|");
  16.     printf("\nXOR-Verknuepfung: \t^");
  17.     printf("\nXNOR-Verknuepfung: \t=");
  18.     printf("\nNAND-Verknuepfung: \t-");
  19.     printf("\n");
  20.     printf("\nGebe ein Verknuepfungszeichen ein: ");
  21.     scanf("%c", &verknuepfungInput);
  22.     getchar();
  23.     if(verknuepfungInput == '&' || verknuepfungInput == '|' || verknuepfungInput == '^' || verknuepfungInput == '=' || verknuepfungInput == '-')
  24.     {
  25.  
  26.         printf("\nGebe die erste boolsche Zahl ein: ");
  27.         scanf("%d", &input1);
  28.         getchar();
  29.         if(input1 == 1 || input1 == 0)
  30.         {
  31.  
  32.             printf("\nGebe die zweite boolsche Zahl ein: ");
  33.             scanf("%d", &input2);
  34.             getchar();
  35.  
  36.             if(input2 == 1 || input2 == 0)
  37.             {
  38.  
  39.  
  40.                 if(verknuepfungInput == '&')
  41.                 {
  42.  
  43.                     resultat = input1 & input2;
  44.  
  45.                     printf("\n");
  46.                     printf("\n");
  47.                     printf("Ausgabe: %d", resultat);
  48.                     printf("\n");
  49.                     printf("\n");
  50.  
  51.                 }
  52.  
  53.                 if(verknuepfungInput == '|')
  54.                 {
  55.  
  56.                     resultat = input1 || input2;
  57.  
  58.                     printf("\n");
  59.                     printf("\n");
  60.                     printf("Ausgabe: %d", resultat);
  61.                     printf("\n");
  62.                     printf("\n");
  63.  
  64.                 }
  65.  
  66.                 if(verknuepfungInput == '^')
  67.                 {
  68.  
  69.                     resultat = input1 ^ input2;
  70.  
  71.                     printf("\n");
  72.                     printf("\n");
  73.                     printf("Ausgabe: %d", resultat);
  74.                     printf("\n");
  75.                     printf("\n");
  76.  
  77.                 }
  78.  
  79.                 if(verknuepfungInput == '=')
  80.                 {
  81.  
  82.                     resultat = input1 ^ input2;
  83.  
  84.                     if(resultat == 1)
  85.                     {
  86.                         resultat = 0;
  87.                     }
  88.                     else if(resultat == 0)
  89.                     {
  90.                         resultat = 1;
  91.                     }
  92.  
  93.                     printf("\n");
  94.                     printf("\n");
  95.                     printf("Ausgabe: %d", resultat);
  96.                     printf("\n");
  97.                     printf("\n");
  98.                 }
  99.  
  100.                 if(verknuepfungInput == '-')
  101.                 {
  102.  
  103.                     resultat = input1 & input2;
  104.  
  105.                     if(resultat == 1)
  106.                     {
  107.                         resultat = 0;
  108.                     }
  109.                     else if(resultat == 0)
  110.                     {
  111.                         resultat = 1;
  112.                     }
  113.                     printf("\n");
  114.                     printf("\n");
  115.                     printf("Ausgabe: %d", resultat);
  116.                     printf("\n");
  117.                     printf("\n");
  118.  
  119.                 }
  120.  
  121.  
  122.  
  123.             }
  124.             else
  125.             {
  126.  
  127.                 printf("\nDie zweite eingegebene Zahl ist nicht 1 oder 0");
  128.                 return 0;
  129.  
  130.             }
  131.  
  132.  
  133.         }
  134.         else
  135.         {
  136.             printf("\nDie erste eingegebene Zahl ist nicht 1 oder 0");
  137.             return 0;
  138.         }
  139.  
  140.     }
  141.     else
  142.     {
  143.         printf("\nDas eingegebene Verknuepfungszeichen ist nicht & oder | oder ^ oder = oder -");
  144.         return 0;
  145.     }
  146.  
  147.  
  148.  
  149.     return 0;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement