C program to sum two integers
1
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
2
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.
3
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.
4
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.
5
Name:
Anonymous
2011-06-09 17:18
void main(x,y){
if(int x != "5")
return y+y;
printf("%d",xy);
}
6
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.
7
Name:
!!kCq+A64Losi56ze
2011-06-09 17:33
>>5
That code won't even compile on my Linux box.
8
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.
9
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); }
10
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);}
11
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);}
12
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);}
13
Name:
Anonymous
2011-06-09 21:36
>>12
Disregard that, it doesn't work.
14
Name:
Anonymous
2011-06-09 23:37
google "c program to sum two integers"
this thread = first result
15
Name:
Anonymous
2011-06-10 0:40
What the fuck is this shit?
16
Name:
Anonymous
2011-06-10 0:54
17
Name:
Anonymous
2011-06-10 1:13
18
Name:
Anonymous
2011-06-10 4:40
19
Name:
Anonymous
2011-06-10 4:40
int main(int x, int y) {
return x+y;
}
20
Name:
Anonymous
2011-06-10 4:44
x##y
21
Name:
Anonymous
2011-06-10 6:15
>>19
under/overflow prone
22
Name:
Anonymous
2011-06-10 6:33
(+ x y)
23
Name:
Anonymous
2011-06-10 6:49
>>22
failure to under/overflow prone
24
Name:
Anonymous
2011-06-10 7:18
>>22
needs moar contracts
25
Name:
Anonymous
2011-06-10 8:47
print n+m
26
Name:
Anonymous
2011-06-10 9:48
27
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;
}
28
Name:
Anonymous
2011-06-10 18:48
BAMPV AVTISMÆ
29
Name:
Anonymous
2011-06-10 18:50
SAGV AVTISMÆ
30
Name:
Anonymous
2011-06-10 18:53
31
Name:
Anonymous
2011-06-11 4:33
∧_∧ ∧_∧ ∧_∧ ∧_∧ ∧_∧
( ・∀・) ( `ー´) ( ´∀`) ( ゚ ∀゚ ) ( ^∀^)
( つ┳∪━━∪━∪━━∪━∪━∪━┳⊂ つ
| | | ┃This thread has peacefully ended.┃ | | |
(__)_) ┻━━━━━━━━━━━━━━┻ (__)_) Thank you.
32
Name:
Anonymous
2011-06-11 13:20
>>27
Doesn't work with negative numbers.
33
Name:
Anonymous
2011-06-11 14:28
>>28
Apparently some autismo spammed /proggles/ with
thy will be done.
BAMPV AVTISMÆ.
Huh.
34
Name:
Anonymous
2011-06-11 14:29
>>32
>sum two integers
>Doesn't work with negative numbers.
35
Name:
Anonymous
2011-06-11 14:37
>>34
Integers are not naturals.
IHBT
36
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.
37
Name:
Anonymous
2011-06-11 15:14
38
Name:
Anonymous
2011-06-11 15:23
N
U
Z
39
Name:
Anonymous
2011-06-11 15:28
40
Name:
Anonymous
2011-06-11 15:36
>>39
.◠. ◝◯∪◯◜ .◠.
AUTISM
.◠. ◝◯∪◯◜ .◠.
41
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.
42
Name:
Anonymous
2011-06-11 18:50
>>41
TIL that outsiders think that those are
/prog/ riders.
43
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.
44
Name:
Anonymous
2011-06-13 19:57
45
Name:
Anonymous
2011-06-14 4:19