int main(){ bigint* a = int_to_bigint(283743); bigint* b = int_to_bigint(27); printf("substraction : %llx\n",bigint_to_int(subtraction(a, b))); printf("division : %llx\n",bigint_to_int(divide(a, b))); }
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; }
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; }