#include <stdio.h>

int main()
{
        int a[8] = {1,0,1,1,0,0,1,1};
        int b[8] = {1,0,1,1,0,0,1,1};
        int c[9] = {0};

        int size = sizeof(a)/sizeof(a[0]);

        int i;
        int carry = 0;
        for (i = size-1; i >= 0; i--) {
                if (a[i] && b[i]) {
                        if (carry) {
                                c[i+1] = 1;
                        } else
                                carry = 1;
                } else if (a[i] || b[i]) {
                        if (!carry) {
                                c[i+1] = 1;
                        }
                } else if (carry){
                        carry = 0;
                        c[i+1] = 1;
                }
        }
        c[i+1] = carry;

        printf("Printing summed array\n");      
        for (i = 0; i < size+1; i++) {
                printf("%d ", c[i]);
        }
        printf("\n");
}


On Wed, Jun 1, 2011 at 8:46 AM, D.N.Vishwakarma@IITR <deok...@gmail.com> wrote:
> There are two n length array A[1...n] ,B[1...n] in which n-bit binary
> integers are stored... We have to sum these two integers and store it in n+1
> length array C[1...n+1] in binary form
>
> --
> With Regards
> Deoki Nandan Vishwakarma
> IITR MCA
> Mathematics Department
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to