示例#1
0
void do_print_all (stack *stack) {
   DEBUGS ('m', show_stack (stack));
   int size = size_stack (stack);
   for (int index = 0; index < size; ++index) {
      print_bigint (peek_stack (stack, index));
   }
}
示例#2
0
void do_print (stack *stack) {
  if (peek_stack (stack, 0) != NULL){
    print_bigint (peek_stack (stack, 0), stdout);
  } else {
    fprintf(stderr, "mydc: stack empty\n");
  }
}
int main(void) {
	bigint_t a = init_bigint(123, 10);
	bigint_t b = init_bigint(111, 10);

	print_bigint(a);
	printf("\n");
	print_bigint(b);
	printf("\n");

	bigint_t r = add(a,b);

	print_bigint(r);
	printf("\n");

	return 0;
}
示例#4
0
void do_print_all (stack *stack) {
  int size = size_stack (stack);
  for (int index = 0; index < size; ++index) {
    if (peek_stack(stack, index) != NULL){
      print_bigint (peek_stack (stack, index), stdout);
    }
  }
}
示例#5
0
文件: main.c 项目: zero14777/My-Stuff
void do_print (stack *stack) {
   DEBUGS ('m', show_stack (stack));
   if (empty_stack(stack)) {
      fprintf(stderr, "mydc: stack empty\n");
   }
   else {
      print_bigint (peek_stack (stack, 0), stdout);
   }
}
示例#6
0
int main() 
{
    int i,j;
    printf("Factorial of:");
    scanf("%d",&i);
    bigint k;
    k=int_to_bigint(1);
    for (j=i;j>0;j--)
    	{
    	k=bigint_mul(k,int_to_bigint(j));
  		}
print_bigint(k);
// print_bigint(bigint_mul(make_bigint("128938499999999"),make_bigint("11123455544444")));
// printf("%d ",compare_bigint(int_to_bigint(444),int_to_bigint(4)));
//print_bigint(bigint_mul(make_bigint("-77777777777666666666666666"),make_bigint("-76777777777776564534467687")));
//print_bigint(make_bigint("23898293829389238239"));
 return(0); 
 }
int main(int argc, char* argv[]) {
  int n,i;
  scanf("%d",&n);
  bigint num,temp;
  char str[2]="1";
  num=make_bigint(str);
  //printf("%s %d %d\n",num.arr,strlen(num.arr),num.sign);
  //print_bigint(num);
  //printf("\n");
  for(i=1;i<=n;i++){
    temp=int_to_bigint(i);
    num=bigint_mul(num,temp);
    //num.arr[strlen(num.arr)]='\0';
    //print_bigint(num);
  }
  //num.arr[strlen(num.arr)]='\0';
  //printf("%d\n",strlen(num.arr));
  //printf("%s\n",num.arr);
  print_bigint(num);
  return 0;
}
示例#8
0
int main(void) {
    char * bigint1 = (char *)malloc(int_max * sizeof(char));
    char * bigint2 = (char *)malloc(int_max * sizeof(char));
    char * bigint3 = (char *)malloc(int_max * sizeof(char));
    char * bigintsum = (char *)malloc(int_max * sizeof(char));
    char * bigintsub = (char *)malloc(int_max * sizeof(char));
    char * bigintmul = (char *)malloc(int_max * sizeof(char));

    memset(bigint1, 0, int_max);
    memset(bigint2, 0, int_max);
    memset(bigint3, 0, int_max);
    memset(bigintsum, 0, int_max);
    memset(bigintsub, 0, int_max);
    memset(bigintmul, 0, int_max);

    double_2_bigint(bigint1, 7462911385);
    double_2_bigint(bigint2, 9800724324238);
    string_2_bigint(bigint3, "-4399000324898602398927826786492023650000000000000000000043242340000");
    bigint_sum(bigint1, bigint2, bigintsum);
    bigint_substract(bigint1, bigint2, bigintsub);
    bigint_mul(bigint1, bigint3, bigintmul);

    print_bigint(bigint1);
    print_bigint(bigint2);
    printf("large? %d\n", bigint_ge(bigint1, bigint2));
    printf("small? %d\n", bigint_le(bigint1, bigint2));
    printf("equal? %d\n", bigint_eq(bigint1, bigint2));
    print_bigint(bigint3);
    print_bigint(bigintsum);
    print_bigint(bigintsub);
    print_bigint(bigintmul);

    free(bigint1);
    free(bigint2);
    free(bigint3);
    free(bigintsum);
    free(bigintsub);
    free(bigintmul);
    return 0;
}
示例#9
0
void do_print (stack *stack) {
   DEBUGS ('m', show_stack (stack));
   print_bigint (peek_stack (stack, 0));
}
示例#10
0
int main( int argc, char* argv[] )
{
    char cmd[ BUF_SIZE ];
    // NOTE: Uncomment this once you've implemented this function
       bigint result = init_bigint();
      //bigint result;
    // At the end of every arithmetic operation update the result.

    // In an infinite loop, get input from user
    while( 1 )
    {
        char* op = NULL; // Store the operation
        // Get a line of input from the user
        fgets( cmd, BUF_SIZE, stdin );

        // Parse the line using strtok
        // Note: Given a string like "a b c d", strtok returns "a" the first
        // time it's called, and "b", "c", "d" and NULL subsequently, if the
        // first argument is NULL. Read the manpage for more details
        op = strtok( cmd, " " );
        // If the last line is a new line, make it a null character
        int len = strlen( op );
        if( op[ len-1 ] == '\n' )
          op[ len-1 ] = 0;
        
        // Match the operation, and do appropriate action
        if( strcmp( op, "quit" ) == 0 || op[0] == EOF )
        {
          // Quit when you see this
          break;
        }
        else if( strcmp( op, "set" ) == 0 )
        {
          // set <data>
          // Sets a big int value to data
         
          int data;
          if( read_args1( &data ) )
          {
            // NOTE: This printf line has been added to help debug. Should be
            // removed before submitting
           // printf( "Setting value as %d\n", data );
            // NOTE: Uncomment this once you've implemented this function
             result = int_to_bigint(data);
          }
        }
        
        else if( strcmp( op, "add" ) == 0 )
        {
          // add <num1> <num2> 
          // Adds two bigints and then prints the result
          
          char num1[512];
          char num2[512];
          if( read_args2( num1, num2 ) )
          {
            // NOTE: This printf line has been added to help debug. Should be
            // removed before submitting
            //printf( "Add %s and %s\n", num1, num2 );
            // NOTE: Uncomment this once you've implemented this function
             bigint a = make_bigint(num1);
             bigint b = make_bigint(num2);
             result = bigint_add( a, b);
             print_bigint(result);
          }
        }
        
        else if( strcmp( op, "sub" ) == 0 )
        {
          // sub <num1> <num2> 
          // Subtracts two bigints and then prints the result
          
          char num1[512];
          char num2[512];
          if( read_args2( num1, num2 ) )
          {
            // NOTE: This printf line has been added to help debug. Should be
            // removed before submitting
            //printf( "Subtract %s and %s\n", num1, num2 );
            // NOTE: Uncomment this once you've implemented this function
             bigint a = make_bigint(num1);
             bigint b = make_bigint(num2);
             result = bigint_sub( a, b);
             print_bigint(result);
	     printf("\n");
          }
        }
        
        else if( strcmp( op, "mul" ) == 0 )
        {
          // mul <num1> <num2> 
          // Multiplies two bigints and then prints the result
          
          char num1[512];
          char num2[512];
          if( read_args2( num1, num2 ) )
          {
            // NOTE: This printf line has been added to help debug. Should be
            // removed before submitting
            //printf( "Multiply %s and %s\n", num1, num2 );
            // NOTE: Uncomment this once you've implemented this function
             bigint a = make_bigint(num1);
             bigint b = make_bigint(num2);
             result = bigint_mul( a, b);
             print_bigint(result);
          }
        }
        else if( strcmp( op, "div" ) == 0 )
        {
          // add <num1> <num2> 
          // Adds two bigints and then prints the result
          
          char num1[512];
          char num2[512];
          if( read_args2( num1, num2 ) )
          {
            // NOTE: This printf line has been added to help debug. Should be
            // removed before submitting
            //printf( "Divide %s and %s\n", num1, num2 );
            // NOTE: Uncomment this once you've implemented this function
             bigint a = make_bigint(num1);
             bigint b = make_bigint(num2);
             result = bigint_div( a, b);
             print_bigint(result);
          }
        }
        else
        {
          printf( "Invalid command\n" );
        }

    }

    return 0;
}