Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C program to sum two integers

Name: Anonymous 2011-06-09 16:55

input:
 stdin 0 -> progname :: string
 stdin 1 -> x :: string
 stdin 2 -> y :: string

output:
 stdout -> x + y :: string

programming language:
 C99

considerations:
 security paranoid programming

Name: Anonymous 2011-06-10 10:22


#include <stdio.h>
#include <string.h>

static const char *a1;
static const char *a2;

static const char *b1;
static const char *b2;

static void full_adder(int A, int B, int C) {
        int S = A + B + C;

        if (S == 0 && a2 == a1 && b2 == b1)
                return;

        full_adder(a2 == a1 ? 0 : *--a2 - '0',
                   b2 == b1 ? 0 : *--b2 - '0',
                   S / 10);

        putchar(S % 10 + '0');
}

int main(int argc, char **argv) {
        if (argc != 3)
                return 1;

        a1 = argv[1];
        a2 = argv[1] + strlen(argv[1]) - 1;
        b1 = argv[2];
        b2 = argv[2] + strlen(argv[2]) - 1;

        full_adder(*a2 - '0', *b2 - '0', 0);
        putchar('\n');

        return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List