int main(void) { double min, max; fac_one_line_t params; flint_rand_t state; int i; flint_randinit(state); params.composites = flint_malloc(1024*sizeof(ulong)); printf("factor_one_line:\n"); for (i = 4; i <= 64; i++) { fill_array(params.composites, i, state); params.bits = i; prof_repeat(&min, &max, sample, ¶ms); printf("bits = %d, time is %.3f us\n", i, max/(double)ITERS); } flint_randclear(state); flint_free(params.composites); return 0; }
/* VTOC in sector 29 */ int get_vtoc(struct diskpart *array, char *buff, int start, void *driver_info, int (*bottom_read_fun)(), char *name, int max_part) { struct evtoc *evp; int n,i; struct disklabel lpl; struct disklabel *lp = &lpl; #if (PARTITION_DEBUG) printf("Read VTOC.\n"); #endif (*bottom_read_fun)(driver_info, start +PDLOCATION, buff); evp = (struct evtoc *)buff; if (evp->sanity != VTOC_SANE) { #if (PARTITION_DEBUG) printf("%s evtoc corrupt or not found\n", name); #endif return(0); } n = min(evp->nparts,max_part); /* no longer DISKLABEL limitations... */ #if 0 n = (evp->nparts > MAXPARTITIONS) ? MAXPARTITIONS : evp->nparts; #endif 0 for (i = 0; i < n; i++) fill_array(&array[i], /* mybase + */ evp->part[i].p_start, evp->part[i].p_size, NULL, 0, DISKPART_NONE, FS_BSDFFS); return(n); /* (evp->nparts) */ }
/* main function */ int main() { int16_t my_array[100]; fill_array(my_array, 100); printf("Sum was %d\n", sum_array(my_array, 100)); return 0; }
int main() { int *p_array = NULL; int key; /* Element to be Searched & Deleted from the Array */ printf ("\nEnter the Size of the Array: "); scanf ("%d", &size); p_array = malloc(size*sizeof(int)); if (NULL==p_array) { printf ("\nMemory Allocation Failed !\n"); exit (EXIT_FAILURE); } fill_array(p_array); printf ("\nOriginal Array:\n"); print_array(p_array); printf ("\nEnter the Key Element: "); scanf ("%d", &key); remove_fragmentation (p_array, key); printf ("\nFinal Array:\n"); print_array(p_array); return 0; }
int main(int argc, char *argv[]) { // Need a length if (argc < 2) errx(1, "missing array len"); size_t len = strtoul(argv[1], NULL, 10); // Create and fill array int *arr = malloc(len * sizeof (int)); fill_array(arr, len); // Print the array print_array(arr, len); // Sort array using your code select_sort(arr, len); // Print it again print_array(arr, len); // Assertion: verify that array // is sorted assert(is_sorted(arr, len)); return 0; }
int main(void) { int numbers[NUM_ELEMENTS] = {0}; fill_array(numbers, NUM_ELEMENTS); print_array(numbers, NUM_ELEMENTS); print_largest_value(numbers, NUM_ELEMENTS); print_average(numbers, NUM_ELEMENTS); return 0; }
int main(void) { char a[LENGTH] = {0}; char b[LENGTH] = {0}; printf("Please enter the number of elements in set A: "); int num_a; scanf("%d", &num_a); fill_array(a, num_a, "A"); printf("Please enter the number of elements in set B: "); int num_b; scanf("%d", &num_b); fill_array(b, num_b, "B"); print_union(a, b, LENGTH); print_intersection(a, b, LENGTH); return 0; }
void test_basic_diffusion() { // Create an array of temperatures with a spike in the middle double u[100]; fill_array(100, u, 0.0); u[50] = 100.0; // Create borders border_t a = {0.0, {0.0}, {0.0}}, b = {99.0, {0.0}, {0.0}}; // Run an iteration phase_update(&a, &b, u, &material); // Check temperatures ASSERT( "Should not change unrelated temperatures", double_equal(u[25], 0.0) && double_equal(u[75], 0.0) && double_equal(u[48], 0.0) && double_equal(u[52], 0.0) ); ASSERT( "Spreads temperature in accordance with the numeric heat equation", double_equal(u[49], 100.0) && double_equal(u[50], -100.0) && double_equal(u[51], 100.0) ); // Run another iteration! phase_update(&a, &b, u, &material); ASSERT( "Should not change unrelated temperatures", double_equal(u[25], 0.0) && double_equal(u[75], 0.0) && double_equal(u[47], 0.0) && double_equal(u[53], 0.0) ); ASSERT( "Spreads temperature in accordance with the numeric heat equation", double_equal(u[48], 100.0) && double_equal(u[49], -200.0) && double_equal(u[50], 300.0) && double_equal(u[51], -200.0) && double_equal(u[52], 100.0) ); }
int main(void) { long n; printf(" enter the number of elements to be entered : "); scanf("%ld",&n); long sort[n]; fill_array(sort, n); printf(" the number of inversions : %ld\n",count_and_merge_sort(sort,n)); return (0); }
void test_near_borders() { // Create an array of temperatures... double u[100]; fill_array(100, u, 0.0); // Create borders border_t a = {10.5, {0.0, 100.0}, {0.0}}, b = {20.5, {100.0, 0.0}, {0.0}}; // Run an iteration phase_update(&a, &b, u, &material); ASSERT( "Temperatures spread correctly near borders", double_equal(u[11], 800.0/3.0) && double_equal(u[20], 800.0/3.0) ); ASSERT( "No other temperatures changed", double_equal(u[10], 0.0) && double_equal(u[12], 0.0) && double_equal(u[19], 0.0) && double_equal(u[21], 0.0) ); // Reset border temperatures and do second iteration a.u[1] = 100.0; b.u[0] = 100.0; phase_update(&a, &b, u, &material); ASSERT( "Temperatures spread correctly near borders", double_equal(u[11], -1600.0/3.0) && double_equal(u[20], -1600.0/3.0) ); ASSERT( "No other temperatures changed", double_equal(u[10], 0.0) && double_equal(u[13], 0.0) && double_equal(u[18], 0.0) && double_equal(u[21], 0.0) ); }
int main(int argc, char *argv[]) { FILE *myFile = fopen(argv[1], "r"); int first_person_total_number_of_times, i; int * first_person_avail_times; // Fill out the arrays with the three people's available times fill_array(myFile, &first_person_avail_times, &first_person_total_number_of_times); fill_array(myFile, &second_person_avail_times, &second_person_total_number_of_times); fill_array(myFile, &third_person_avail_times, &third_person_total_number_of_times); // allocate memory for the threads of first person's times pthread_t *tid[first_person_total_number_of_times]; for(i = 0; i < first_person_total_number_of_times; i++) { tid[i] = (pthread_t *) malloc(sizeof(pthread_t)); } // Start the threads to calculate common times for(i = 0; i < first_person_total_number_of_times; i++) { int *first_person_time = (int *) malloc(sizeof(int)); *first_person_time = first_person_avail_times[i]; if( pthread_create( tid[i], NULL, compare_times, (void *) first_person_time)) { fprintf (stderr, "Error creating thread %d\n", i); } } for(i = 0; i < first_person_total_number_of_times; i++) { if(pthread_join(*tid[i], NULL)) { fprintf(stderr, "Error joining with thread %d", i); } } exit(0); }
static int array_read(struct inode * inode, struct file * file,char * buf, int count) { unsigned long page; char *start; int length; int end; unsigned int type, pid; struct proc_dir_entry *dp; if (count < 0) return -EINVAL; if (count > PROC_BLOCK_SIZE) count = PROC_BLOCK_SIZE; if (!(page = __get_free_page(GFP_KERNEL))) return -ENOMEM; type = inode->i_ino; pid = type >> 16; type &= 0x0000ffff; start = NULL; dp = (struct proc_dir_entry *) inode->u.generic_ip; if (dp->get_info) length = dp->get_info((char *)page, &start, file->f_pos, count, 0); else length = fill_array((char *) page, pid, type, &start, file->f_pos, count); if (length < 0) { free_page(page); return length; } if (start != NULL) { /* We have had block-adjusting processing! */ memcpy_tofs(buf, start, length); file->f_pos += length; count = length; } else { /* Static 4kB (or whatever) block capacity */ if (file->f_pos >= length) { free_page(page); return 0; } if (count + file->f_pos > length) count = length - file->f_pos; end = count + file->f_pos; memcpy_tofs(buf, (char *) page + file->f_pos, count); file->f_pos = end; } free_page(page); return count; }
int main() { double arr_of_dbl[MAX_SZ]; unsigned size = fill_array(arr_of_dbl, MAX_SZ); show_array(arr_of_dbl, size); std::cout << std::endl; reverse_array(arr_of_dbl, size); show_array(arr_of_dbl, size); std::cout << std::endl; return 0; }
int main(int argc, char** argv) { int p; float p_step; int i; int size; int* f; int paths_found; if(argc == 1) { p_step = DEFAULT_P_STEP; } else { p_step = strtof(argv[1], NULL); if(p_step==0.0) { fprintf(stderr, "Usage:\n\t%s [p]\n\np: Probability (default: %g)\n", argv[0], DEFAULT_P_STEP); exit(1); } } for(size=10; size <= MAX_SIZE; size*=10) { f = malloc(size*size*sizeof(int)); if(f == NULL) { fprintf(stderr, "Memory Error"); exit(1); } for(p=0; p<1.0/p_step; p++) { paths_found = 0; for(i=0; i<N_STAT; i++) { fill_array(f, size, p*p_step); paths_found += has_path(f, size); } printf("%f %g %d\n", p*p_step, (float)paths_found/N_STAT, paths_found); } printf("\n\n"); free(f); } return 0; }
int main( int argc , char* argv[] ) { int sum , memspace ; int* ptr ; printf( "Enter the number of numbers to be stored in the array\n" ) ; scanf( "%d" , &memspace ) ; /* create array of ints, user decides how big it is */ ptr = ( int* ) malloc ( memspace * sizeof ( int ) ) ; fill_array( ptr , memspace ) ; sum = sum_array( ptr , memspace ) ; printf( "The sum of the elements in your array is %d\n" , sum ) ; free ( ptr ) ; return 0 ; }
int main(int argc, const char* argv[]) { int sort_choice, len, *array, start, finish; struct timeval tm_begin, tm_end; // check for the proper number of arguments if (argc != 3) { fprintf(stderr, "Syntax:\n\t%s <sort algorithm> <problem size>\n", argv[0]); return -1; } sort_choice = atoi(argv[1]); // which sort algorithm to execute len = atoi(argv[2]); // length of array srand( time(NULL) ); // initialize rand based on system time array = ( int* ) malloc((len)* sizeof(int)); fill_array(array, len); // print_array(array, len); gettimeofday(&tm_begin, NULL); // store start time switch (sort_choice) { case 1: insertion_sort(array,len); break; case 2: bubble_sort(array, len); break; case 3: quick_sort(array, 0, len-1); break; case 4: merge_sort(array, 0, len); break; case 5: qsort(array, len, sizeof(int), compare); break; default: printf("\tInvalid sort alogithm selected\n"); return -1; } gettimeofday(&tm_end, NULL); // store end time // print_array(array, len); free(array); start = (tm_begin.tv_usec + tm_begin.tv_sec*1000000); finish = (tm_end.tv_usec + tm_end.tv_sec*1000000); // print results in formated output printf("%d, %d, %d\n",sort_choice, len, finish-start); return 0; }
int main(int argc, char** argv) { int coordinateCount; scanf("%d", &coordinateCount); int board[BOAR_SIZE] = {0}; int temp[BOAR_SIZE] = {0}; fill_array(board, temp, coordinateCount); start_game(board, temp, BOAR_SIZE); print_in_binary(board, BOAR_SIZE); return (EXIT_SUCCESS); }
int main() { int x; int array[max]; int elements; do { printf("Enter number: "); scanf("%d", &x); }while (x<0); elements=fill_array(array, x); print_array(array, elements); prime_num(array, elements); return 0; }
void test_border_temperatures() { // Create an array of temperatures... double u[100]; fill_array(100, u, 0.0); // Create borders border_t a = {10.5, {0.0, 0.0}, {0.0}}, b = {20.5, {0.0, 0.0}, {0.0}}; // Run an iteration phase_update(&a, &b, u, &material); ASSERT( "Temperatures not changed", double_equal(a.u[1], 0.0) && double_equal(b.u[0], 0.0) ); // Set temperatures to something else and run an iteration a.u[1] = 100.0; b.u[0] = 100.0; phase_update(&a, &b, u, &material); ASSERT( "Border temperatures updated correctly", double_equal(a.u[1], -700) && double_equal(b.u[0], -700) ); // Set the temperatures in nearby points u[11] = 100; u[20] = 100; // Run another iteration phase_update(&a, &b, u, &material); ASSERT( "Border temperatures updated correctly", double_equal(a.u[1], 5700.0) && double_equal(b.u[0], 5700.0) ); }
// Play one game void play( char *theWord ) { int numGuess = INCORRECT_GUESSES; char soFar[ MAXWORD ]; int guessesLeft; int result; fill_array( soFar, strlen( theWord ), '*' ); for( ; numGuess > 0; numGuess-- ) { printf( "You have %d guesses left\n\n", numGuess ); result = get_letter( theWord, soFar ); if( result == 1 ) { if( strcmp( soFar, theWord ) == 0 ) { printf( "HOORAY! YOU FIGURED OUT MY WORD!\n" ); printf( "The word you guessed correctly was, in fact, %s.\n", theWord ); printf( "Now send me some Money so my code can be used by everyone!\n\n" ); break; } numGuess++; } else if( result == 0 ) { printf( "Guess again!\n\n" ); printf( "The Word you are trying to figure out so far is:\n\n" ); printf( "%s\n\n", soFar ); } } if( numGuess == 0 ) { printf( "I'm Sorry, but you did not find the word in the amount of guesses!\n\n" ); printf( "The Word you had to figure out was\t%s\n\n", theWord ); printf( "Come play again!\n" ); } }
int main (int argc, char *argv[]) { int wrank, nproc, size, i, level = 0, local_size; double *array, *local_array, *local_left, *local_right, median; MPI_Init(&argc, &argv); /* initialize mpi */ MPI_Comm_size(MPI_COMM_WORLD, &nproc); /* get the number of processors */ MPI_Comm_rank(MPI_COMM_WORLD, &wrank); /* Get my number */ if(argc < 2 && wrank == 0) { printf(wrank == 0 ? "Usage: mpirun -np 4 ./qsort n (where n is the array size)\n" : ""); MPI_Finalize(); return -1; } size = atoi(argv[1]); // allocate whole array if on proc 0 if (wrank == 0) { array = (double *)calloc(size,sizeof(double)); fill_array(array,size); } // allocate local array for each processor local_size = size/nproc; local_array = (double*)calloc(local_size,sizeof(double)); int ttime=timer(); MPI_Scatter(array, local_size, MPI_DOUBLE, local_array, local_size, MPI_DOUBLE, 0, MPI_COMM_WORLD); serial_quicksort(local_array,0,local_size-1); paral_quicksort(0, nproc, MPI_COMM_WORLD, local_array, local_size, array); if(wrank == 0) { ttime=timer()-ttime; printf("procs: %d, Time: %f\n",nproc,ttime/1000000.0); // printf ("\n"); printf(is_sorted(array,size) ? "Success!!!\n" : "Fail!!!\n"); print_array(array,size); } if (wrank == 0) free(array); MPI_Finalize(); return 0; }
int array_add(struct array *arr, const void *data) { assert(arr && data && "Error: array_add bad data"); if (arr->data_amount >= arr->buffer_amount) { //allocate new larger array and copy over existing array void *new_array = calloc(2 * arr->buffer_amount, sizeof(void *)); if (!new_array) return 0; fill_array(new_array, arr->data, arr->buffer_amount); free(arr->data); arr->data = new_array; arr->buffer_amount *= 2; } arr->data[arr->data_amount] = (void *)data; arr->data_amount++; return 1; }
int main(int argc, char *argv[]) { char *base; size_t size = (unsigned) 1 << 4; /* size_t size = (unsigned) 1 << 31; */ base = malloc(sizeof(char) * size); assert(base); fill_array(base, size, sizeof(char), create_element); print_array(stdout, base, size, sizeof(char), print_element); fprintf(stdout, "%s", "\n"); msort(base, size, sizeof(char), compare); print_array(stdout, base, size, sizeof(char), print_element); fprintf(stdout, "%s", "\n"); return 0; }
int main(void) { if(!fill_array()) { printf("A: "); print_matrix(B_data, dim, dim); printf("\nA'A\n"); covariance_fast(B_data, dim, dim); printf("\n"); hshld(B_data, dim, d, e); printf("\ndiags: \n"); print_matrix(B_data, dim, dim); } else { printf("did not get array!\n"); return 1; } }
int main (int argc, string argv[]) { // validate number of arguments if (argc != 2) { printf("Usage: ./binarysearch <array size> \n"); return 1; } // validate length argument int len = strtol(argv[1], NULL, 10); //int len = atoi(argv[1]); if (len <= 0) { printf("Invalid array size argument \n"); return 2; } //max of 2 million for now if (len > 2000000) { len = 2000000; } // populate test array int data[len]; fill_array(data, len); // generate search term int term = get_random_term(len); printf("Array Size: %i \n", len); printf("Random search term: %i \n", term); // perform search int found_index = search(data, len, term); if (found_index < 0) { printf("\n Value %i NOT found in array! \n\n", term); } else { printf("\n Value %i FOUND at array[%i]! \n\n", term, found_index); } return 0; }
int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Enter an integer array size.\n"); return 1; } int size = atoi(argv[1]); int a[size]; fill_array(a, size); print_array(a, size); quicksort(a, a + (size-1)); printf("\n"); print_array(a, size); return 0; }
int main(int argc, char *argv[]) { int indx; int array_size; if (argc > 1) { array_size = atoi(argv[1]); } else { array_size = 1024; } my_array = (int *) malloc(sizeof(int)*array_size); fill_array(array_size); ArraySort(my_array, cmpfun, array_size); free(my_array); return(0); }
int main(int argc, char *argv[]) { int indx; int array_size; if (argc > 1) { array_size = atoi(argv[1]); } else { array_size = 1024; } my_array = (unsigned int *) malloc(sizeof(unsigned int)*array_size); fill_array(array_size); randMemAccess(my_array, array_size); free(my_array); return(0); }
int main() { int na, nb; int k; scanf("%d%d%d", &na, &nb, &k); assert(k < na + nb); int* arr = (int*)malloc(sizeof(int) * (na + nb)); fill_array(arr, na + nb); int* a = arr; int* b = a + na; qsort(a, na, sizeof(int), cmp); qsort(b, nb, sizeof(int), cmp); int kth = kth_of_two_sorted(a, na, b, nb, k); qsort(arr, na + nb, sizeof(int), cmp); assert(arr[k] == kth); free(arr); return 0; }
int ArrayTest::prepare_test_case( int test_case_idx ) { int code = 1; size_t max_arr = test_array.size(); vector<vector<Size> > sizes(max_arr); vector<vector<Size> > whole_sizes(max_arr); vector<vector<int> > types(max_arr); size_t i, j; RNG& rng = ts->get_rng(); bool is_image = false; for( i = 0; i < max_arr; i++ ) { size_t sizei = std::max(test_array[i].size(), (size_t)1); sizes[i].resize(sizei); types[i].resize(sizei); whole_sizes[i].resize(sizei); } get_test_array_types_and_sizes( test_case_idx, sizes, types ); for( i = 0; i < max_arr; i++ ) { size_t sizei = test_array[i].size(); for( j = 0; j < sizei; j++ ) { unsigned t = randInt(rng); bool create_mask = true, use_roi = false; CvSize size = cvSize(sizes[i][j]), whole_size = size; CvRect roi = CV_STRUCT_INITIALIZER; is_image = !cvmat_allowed ? true : iplimage_allowed ? (t & 1) != 0 : false; create_mask = (t & 6) == 0; // ~ each of 3 tests will use mask use_roi = (t & 8) != 0; if( use_roi ) { whole_size.width += randInt(rng) % 10; whole_size.height += randInt(rng) % 10; } cvRelease( &test_array[i][j] ); if( size.width > 0 && size.height > 0 && types[i][j] >= 0 && (i != MASK || create_mask) ) { if( use_roi ) { roi.width = size.width; roi.height = size.height; if( whole_size.width > size.width ) roi.x = randInt(rng) % (whole_size.width - size.width); if( whole_size.height > size.height ) roi.y = randInt(rng) % (whole_size.height - size.height); } if( is_image ) { test_array[i][j] = cvCreateImage( whole_size, icvTsTypeToDepth[CV_MAT_DEPTH(types[i][j])], CV_MAT_CN(types[i][j]) ); if( use_roi ) cvSetImageROI( (IplImage*)test_array[i][j], roi ); } else { test_array[i][j] = cvCreateMat( whole_size.height, whole_size.width, types[i][j] ); if( use_roi ) { CvMat submat, *mat = (CvMat*)test_array[i][j]; cvGetSubRect( test_array[i][j], &submat, roi ); submat.refcount = mat->refcount; *mat = submat; } } } } } test_mat.resize(test_array.size()); for( i = 0; i < max_arr; i++ ) { size_t sizei = test_array[i].size(); test_mat[i].resize(sizei); for( j = 0; j < sizei; j++ ) { CvArr* arr = test_array[i][j]; test_mat[i][j] = cv::cvarrToMat(arr); if( !test_mat[i][j].empty() ) fill_array( test_case_idx, (int)i, (int)j, test_mat[i][j] ); } } return code; }