Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //By Bartek//
- #include<stdio.h>
- #include <conio.h>
- int sum(int a, int b, int c);
- int carry(int a, int b, int c);
- int main()
- {
- int a[4] = {0}, b[4] = {0}, c = 0, result[4] = {0}, i = 0;
- printf("Podaj A[MSB,...,LS: ");
- scanf("%d%d%d%d", &a[3], &a[2], &a[1], &a[0]);
- printf("Podaj B[MSB,...,LS: ");
- scanf("%d%d%d%d", &b[3], &b[2], &b[1], &b[0]);
- for(i = 0; i < 4; i++)
- {
- result[i] = sum(a[i], b[i], c);
- c = carry(a[i], b[i], c);
- }
- printf("Wynik[C,MSB,...,LS: %d %d %d %d %d\n", c, result[3], result[2], result[1], result[0]);
- getch();
- }
- int sum(int a, int b, int c)
- {
- return c ^ a ^ b;
- }
- int carry(int a, int b, int c)
- {
- return (a & b) | (c & (a ^ b));
- }
Advertisement
Add Comment
Please, Sign In to add comment