fork download
  1. #include <stdio.h>
  2.  
  3. /* 半加算器 */
  4. /* a, b : 入力 s : 和 c : 桁上げ */
  5. void half_adder(int a, int b, int *s, int *c)
  6. {
  7. *s = a ^ b;
  8. *c = a & b;
  9.  
  10. printf("半加算器の真理値表 : a = %d b = %d s = %d c = %d\n", a, b, *s, *c);
  11. }
  12.  
  13. /* 全加算器 */
  14. /* a, b : 入力 x : 下位から桁上げ s : 和 c: 桁上げ */
  15. void full_adder(int a, int b, int x, int *s, int *c)
  16. {
  17. int s1, c1, s2, c2;
  18.  
  19. half_adder(a, b, &s1, &c1);
  20. half_adder(s1, x, &s2, &c2);
  21. *c = c1 | c2;
  22. *s = s2;
  23.  
  24. printf("全加算器の真理値表 : a = %d b = %d x = %d s = %d c = %d\n\n", a, b, x, *s, *c);
  25. }
  26.  
  27. int main(void)
  28. {
  29. int a, b, x, s, c;
  30.  
  31. for (x = 0; x <= 1; x++)
  32. for (b = 0; b <= 1; b++)
  33. for (a = 0; a <= 1; a++) {
  34. full_adder(a, b, x, &s, &c);
  35. }
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
半加算器の真理値表 : a = 0 b = 0 s = 0 c = 0
半加算器の真理値表 : a = 0 b = 0 s = 0 c = 0
全加算器の真理値表 : a = 0 b = 0 x = 0 s = 0 c = 0

半加算器の真理値表 : a = 1 b = 0 s = 1 c = 0
半加算器の真理値表 : a = 1 b = 0 s = 1 c = 0
全加算器の真理値表 : a = 1 b = 0 x = 0 s = 1 c = 0

半加算器の真理値表 : a = 0 b = 1 s = 1 c = 0
半加算器の真理値表 : a = 1 b = 0 s = 1 c = 0
全加算器の真理値表 : a = 0 b = 1 x = 0 s = 1 c = 0

半加算器の真理値表 : a = 1 b = 1 s = 0 c = 1
半加算器の真理値表 : a = 0 b = 0 s = 0 c = 0
全加算器の真理値表 : a = 1 b = 1 x = 0 s = 0 c = 1

半加算器の真理値表 : a = 0 b = 0 s = 0 c = 0
半加算器の真理値表 : a = 0 b = 1 s = 1 c = 0
全加算器の真理値表 : a = 0 b = 0 x = 1 s = 1 c = 0

半加算器の真理値表 : a = 1 b = 0 s = 1 c = 0
半加算器の真理値表 : a = 1 b = 1 s = 0 c = 1
全加算器の真理値表 : a = 1 b = 0 x = 1 s = 0 c = 1

半加算器の真理値表 : a = 0 b = 1 s = 1 c = 0
半加算器の真理値表 : a = 1 b = 1 s = 0 c = 1
全加算器の真理値表 : a = 0 b = 1 x = 1 s = 0 c = 1

半加算器の真理値表 : a = 1 b = 1 s = 0 c = 1
半加算器の真理値表 : a = 0 b = 1 s = 1 c = 0
全加算器の真理値表 : a = 1 b = 1 x = 1 s = 1 c = 1