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

Pages: 1-4041-

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: !!kCq+A64Losi56ze 2011-06-09 17:10

stdin 0 is a *nix thing. Now stop acting like a little girl, get with the program, and use the standard stdin. Ie...

FILE *stidn;

Or better yet, use a real programming language like BASIC.

Name: !!kCq+A64Losi56ze 2011-06-09 17:11

Or you can learn lisp and end up working as a shift manager at your local taco bell.

Name: Anonymous 2011-06-09 17:15

>>2
The opening poster is considering C99 in *nix, so there's nothing wrong with her nomenclature for standard input.

Name: Anonymous 2011-06-09 17:18

void main(x,y){
if(int x != "5")
return y+y;
printf("%d",xy);
}

Name: Anonymous 2011-06-09 17:20

>>5
oops forgot that you need to but "PutChar();" on the line before the void. other than that it is professional code used at my work to sum factorials when dividing the stock market.

Name: !!kCq+A64Losi56ze 2011-06-09 17:33

>>5
That code won't even compile on my Linux box.

Name: Anonymous 2011-06-09 19:29


#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>

signed int main(int argc, char *argv[])
{
 enum
 {
  BASE = 10,
  N_ARGS = 3,
  ZERO = 0,
  ONE = 1,
  TWO = 2
 };

 auto mpz_t x;
 auto mpz_t y;

 signed int ret_val = EXIT_SUCCESS;

 if (fclose(stdin) == EOF || argc != N_ARGS)
 {
  ret_val = EXIT_FAILURE;
  goto BYE;
 }

 mpz_init(x);
 mpz_init(y);

 if (mpz_set_str(x, argv[ONE], BASE) != ZERO || mpz_set_str(y, argv[TWO], BASE) != ZERO)
 {
  ret_val = EXIT_FAILURE;
  goto CLEAN;
 }

 mpz_add(x, x, y);

 if (mpz_out_str(NULL, BASE, x) == ZERO || fputc('\n',stdout) <= ZERO)
  ret_val = EXIT_FAILURE;

 CLEAN:
 mpz_clear(x);
 mpz_clear(y);

 BYE:
 return ret_val;
}


Security paranoia is missing, but someone will probably pick it up.

Name: Anonymous 2011-06-09 20:51

#include <stdio.h>
#include <gmp.h>

int main(int argc, char *argv[argc])
{ mpz_t s, n; mpz_inits(s, n, NULL);
  for(int i = 1; i < argc; mpz_add(s, s, n))
    mpz_set_str(n, argv[i++], 10);
  mpz_out_str(stdout, 10, s);
  mpz_clears(s, n, NULL); }

Name: Anonymous 2011-06-09 21:02

>>9

#include<stdio.h>
#include<gmp.h>
main(int c,char**v){mpz_t s,n;mpz_inits(s,n,NULL);while(argv){mpz_set_str(n,argv++,10);mpz_add(s,s,n);}mpz_out_str(stdout,10,s);mpz_clears(s,n,NULL);}

Name: Anonymous 2011-06-09 21:11

>>10
#include<stdio.h>
#include<gmp.h>
main(int c,char**v){mpz_t s,n;for(mpz_inits(s,n,0);++v;mpz_add(s,s,n))mpz_set_str(n,v,10);mpz_out_str(stdout,10,s);mpz_clears(s,n,0);}

Name: Anonymous 2011-06-09 21:31


#include<stdio.h>
#include<gmp.h>
#define m mpz_
main(int c,char**v){m#t s,n;for(m#inits(s,n,0);++v;m#add(s,s,n))m#set_str(n,v,10);m#out_str(stdout,10,s);m#clears(s,n,0);}

Name: Anonymous 2011-06-09 21:36

>>12
Disregard that, it doesn't work.

Name: Anonymous 2011-06-09 23:37

google "c program to sum two integers"
this thread = first result

Name: Anonymous 2011-06-10 0:40

What the fuck is this shit?

Name: Anonymous 2011-06-10 0:54

Name: Anonymous 2011-06-10 1:13

Name: Anonymous 2011-06-10 4:40

Name: Anonymous 2011-06-10 4:40

int main(int x, int y) {
    return x+y;
}

Name: Anonymous 2011-06-10 4:44

x##y

Name: Anonymous 2011-06-10 6:15

>>19
under/overflow prone

Name: Anonymous 2011-06-10 6:33

(+ x y)

Name: Anonymous 2011-06-10 6:49

>>22
failure to under/overflow prone

Name: Anonymous 2011-06-10 7:18

>>22
needs moar contracts

Name: Anonymous 2011-06-10 8:47

print n+m

Name: Anonymous 2011-06-10 9:48

>>21,23
So what?

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;
}

Name: Anonymous 2011-06-10 18:48

BAMPV AVTISMÆ

Name: Anonymous 2011-06-10 18:50

SAGV AVTISMÆ

Name: Anonymous 2011-06-10 18:53

>>29
sagu?

Name: Anonymous 2011-06-11 4:33

  ∧_∧   ∧_∧   ∧_∧   ∧_∧      ∧_∧
 ( ・∀・)   ( `ー´)  ( ´∀`)  ( ゚ ∀゚ )    ( ^∀^)
 (    つ┳∪━━∪━∪━━∪━∪━∪━┳⊂     つ
 | | |  ┃This thread has peacefully ended.┃ | | |
 (__)_) ┻━━━━━━━━━━━━━━┻ (__)_)     Thank you.

Name: Anonymous 2011-06-11 13:20

>>27
Doesn't work with negative numbers.

Name: Anonymous 2011-06-11 14:28

>>28
Apparently some autismo spammed /proggles/ with

thy will be done.

BAMPV AVTISMÆ.


Huh.

Name: Anonymous 2011-06-11 14:29

>>32
>sum two integers
>Doesn't work with negative numbers.

Name: Anonymous 2011-06-11 14:37

>>34
Integers are not naturals. IHBT

Name: Anonymous 2011-06-11 14:50

>>35
If Integer is a wrapper around a type int, and this class forms an equivalence relation... Screw it. I don't think your dumbass ever made it beyond second semester calculus.

Name: Anonymous 2011-06-11 15:14

>>36
ℤ ⊃ ℕ. Thread over.

Name: Anonymous 2011-06-11 15:23

N
U
Z

Name: Anonymous 2011-06-11 15:28

>>38
ZUN

Name: Anonymous 2011-06-11 15:36

>>39
.◠. ◝◯∪◯◜ .◠.
AUTISM
.◠. ◝◯∪◯◜ .◠.

Name: Anonymous 2011-06-11 18:43

TIL that /prog/gers are so dumb that they don't even know that natural numbers are a subset of integer numbers.

Name: Anonymous 2011-06-11 18:50

>>41
TIL that outsiders think that those are /prog/riders.

Name: Anonymous 2011-06-11 19:49

>>41
I don't know which group is worse. The group that has never made it beyond SICP or the group that didn't learn jack shit from undergrad school.

Name: Anonymous 2011-06-13 19:57

>>16-18
more of this

Name: Anonymous 2011-06-14 4:19

http://mitpress.mit.edu/sicp/
http://mitpress.mit.edu/sicp/

http://mitpress.mit.edu/sicp/

sometimes prog makes me feel like a baby. everything hilarious and nonsenseical


http://mitpress.mit.edu/sicp/

    http://mitpress.mit.edu/sicp/
    http://mitpress.mit.edu/sicp/
    http://mitpress.mit.edu/sicp/

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