trojanxem

Untitled

Mar 2nd, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <conio.h>
  3.  
  4. int sum(int a, int b, int c);
  5. int carry(int a, int b, int c);
  6.  
  7. int main()
  8. {
  9.   int a[4] = {0}, b[4] = {0}, c = 0, result[4] = {0}, i = 0;
  10.  
  11.   printf("Podaj A[MSB,...,LS:  ");
  12.   scanf("%d%d%d%d", &a[3], &a[2], &a[1], &a[0]);
  13.  
  14.   printf("Podaj B[MSB,...,LS:  ");
  15.   scanf("%d%d%d%d", &b[3], &b[2], &b[1], &b[0]);
  16.  
  17.   for(i = 0; i < 4; i++)
  18.   {
  19.     result[i] = sum(a[i], b[i], c);
  20.     c = carry(a[i], b[i], c);
  21.   }
  22.    
  23.   printf("Wynik[C,MSB,...,LS: %d %d %d %d %d\n", c, result[3], result[2], result[1], result[0]);
  24.   getch();
  25. }
  26.  
  27. int sum(int a, int b, int c)
  28. {
  29.   return c ^ a ^ b;
  30. }
  31.  
  32. int carry(int a, int b, int c)
  33. {
  34.   return (a & b) | (c & (a ^ b));
  35. }
Advertisement
Add Comment
Please, Sign In to add comment