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

C: sum two integers

Name: Anonymous 2010-12-25 13:53


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

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

 auto mpz_t x;
 auto mpz_t y;
 auto bool ret_val;

 ret_val = true;

 if (argc != N_ARGS)
 {
  ret_val = false;
  goto BYE;
 }

 mpz_init(x);
 mpz_init(y);

 if (mpz_set_str(x, argv[UNO], BASE) != ZERO || mpz_set_str(y, argv[DOS], BASE) != ZERO)
 {
  ret_val = false;
  goto CLEAN;
 }

 mpz_add(x, x, y);

 if (mpz_out_str(NULL, BASE, x) == ZERO || printf("\n") <= ZERO)
  ret_val = false;

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

 BYE:
 return (!ret_val) ? EXIT_FAILURE : EXIT_SUCCESS;
}

Name: Anonymous 2010-12-25 14:02

>>3

no hablan castellano?

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