int main(int argc, const char * argv[]){ clock_t begin = clock(); if(argc == 1){ // standard mode mpz_t numbers[NUMBERS]; list * calculatedFactors[NUMBERS]; int i; mpz_t y; mpz_init_set_ui(y, 1); for (i = 0; i < NUMBERS; i++){ mpz_init(numbers[i]); mpz_inp_str(numbers[i], stdin, 10); } for (i = 0; i < NUMBERS; i++) { reset_timer(); list* factors = createList(); factorize(factors, numbers[i],1, y); calculatedFactors[i] = factors; } for (i = 0; i < NUMBERS; i++){ printFactors(calculatedFactors[i]); } clock_t end = clock(); double tdiff = (((double) end) - ((double)begin)) / CLOCKS_PER_SEC; printf(", %f\n", tdiff); return 0; } else if(strcmp(argv[1], "interactive") == 0){ // interactive mode fprintf(stderr, "Interactive mode!\n"); mpz_t number; mpz_init(number); list * factors = NULL; mpz_t y; mpz_init_set_ui(y, 1); while (1) { mpz_inp_str(number, stdin, 10); reset_timer(); factors = createList(); factorize(factors, number, 1, y); TRACE("PRINTING FACTORS:\n"); printFactors(factors); } return 0; } return 1; }
int main() { unsigned long long int num = 0; int temp = 1; // Tell the user what our bounds are // we are not perfect - we can only go // as far as an unsigned 64-bit int // can hold printf("Enter a number between 0 and 18446744073709551614\n"); // Loop to accept user input // Will exit when the user does not // enter an integer number while(temp == 1) { // Print first, ask later // this is to avoid the printFactors() // being called on what ever was left // when the user breaks the program // with a non-int value printFactors(num); temp = scanf("%llu", &num); } return 0; }
int main(int argc, char* argv[]) { int initRef[1]; initRef[0]= 0; int input = atoi((char *)argv[1]); if (argc < 2) printf("Please run the program by passing correct parameters\n"); input = strtol(argv[1], NULL, 10); if(input<=0) printf("Please enter positive number\n"); else { printf("%d * 1\n",input); printFactors(input,input,initRef); } //_gettch(); return 0; }
void printFactors(int input, int nextFact, int myRef[]) { int temp = nextFact; for (int i = input - 1; i >= 2; i--) { if (input % i == 0) { if (temp > i) temp = i; if ( (i <= nextFact) && (input /i <= nextFact) && (input /i <= i)) { if(myRef[0]==0) printf("%d * %d\n", i, (input /i)); else { for(int k=0;myRef[k]!=0;k++) { if(myRef[k]=='*') printf("%c ",myRef[k]); else printf("%d ",myRef[k]); } printf("%d * %d\n", i, (input /i)); } temp = input / i; } if (i <= nextFact) { int p[4098]; int k=0; for( k=0; myRef[k]!=0;k++) p[k]=myRef[k]; p[k]= i; p[k+1]='*'; p[k+2]=0; printFactors(input / i , temp,p); } } } }