예제 #1
0
파일: at2.c 프로젝트: tusharnarayan/wpi-cs
/* function main begins program execution */
int main( void )
{
  const int MAX_GRADES = 10; //maximum size of the array
  const int MAX_VALID_VALUE = 100; //maximum valid value that user can enter
  int grades[MAX_GRADES]; /* array to store all valid entered grades */
  int array_size; //stores the number of valid inputs that array contains

  /* instructions */
  printf( "\nWelcome \n" );
  printf( "\nEnter numbers. I will print them ,then sort & print them!\n" );
  printf( "\nSignify an end to entries by inputting a negative number.\n" );
  printf( "The maximum number of entries I can take is %d.\n\n", MAX_GRADES );

  /* Call function to get and store input into the array.
     The function returns the number of valid inputs in the array,
     store this value in the variable array_size.*/
  array_size = get_array_input(grades, MAX_GRADES, MAX_VALID_VALUE);

  printf( "\nThe input you gave me is:\n" );
  // call function to print the array
  print_int_array(grades, array_size);
  
  // call function to sort the array
  bubble_sort(grades, array_size);
  
  printf( "\nSorted form of the input is:\n" );
  // call function to print the sorted array
  print_int_array(grades, array_size);
  
  return 0; /* indicate program ended successfully */
} //end of main
void test_multinomial(void){
    double p[SIZE] = { .1, .2, .3, .4 };
    int n[SIZE] = { 0, 0, 0, 0 };
    int numdraws = 100;
    double prob;

    gsl_ran_multinomial(rng, SIZE, numdraws, p, n); 

    printf("gsl_ran_multinomial\t%d\t", numdraws);
    print_double_array(p, SIZE);
    printf("\t");
    print_int_array(n, SIZE);
    printf("\n");

    prob = gsl_ran_multinomial_pdf(SIZE, p, n); 
    printf("gsl_ran_multinomial_pdf\t");
    print_double_array(p, SIZE);
    printf("\t");
    print_int_array(n, SIZE);
    printf("\t%.12f\n", prob);

    prob = gsl_ran_multinomial_lnpdf(SIZE, p, n); 
    printf("gsl_ran_multinomial_lnpdf\t");
    print_double_array(p, SIZE);
    printf("\t");
    print_int_array(n, SIZE);
    printf("\t%.12f\n", prob);
}
예제 #3
0
파일: bubbleSort.c 프로젝트: VisionLiu/poj
int main(){
	int a[SIZE];
    rand_int_array(a,SIZE); 
    print_int_array(a,SIZE); 
	bubbleSort3(a,SIZE);
	print_int_array(a,SIZE); 
    return 0;    

}
예제 #4
0
int main(int argc, char *argv[])
{
    /* The program name, to be passed to usage() */
    char *program_name = argv[0];
    int num_cells;   /* Number of cells in automaton */
    int num_gens;    /* Number of gens for automaton */
    int i;
    int zero_or_one; /* Temp int to fill array */
    int *numbers;    /* Array to be used for automaton */
    int *numbers2;   /* Array used to generate next gen */

    /* If not the correct number of elements, print usage and exit */
    if (argc != 3)
    {
        usage(program_name);
    }

    num_cells = atoi(argv[1]); /* Get num cells from args */
    num_gens = atoi(argv[2]);  /* Get num gens from args */
    /* Dynamically allocate memory for the arrays */
    numbers = (int *) calloc(num_cells, sizeof(int));
    numbers2 = (int *) calloc(num_cells, sizeof(int));
    /* Check to make sure the memory is correctly allocated */
    if (numbers == NULL || numbers2 == NULL)
    {
        fprintf(stderr, "Error! Memory allocation failed!\n");
        exit(1);
    }

    /* Seed the random generator */
    srand(time(NULL));
    /* Fill both arrays with random zeroes and ones */
    for (i = 0; i < num_cells; i++)
    {
        zero_or_one = rand() % 2;
        numbers[i] = zero_or_one;
        numbers2[i] = zero_or_one;
    }

    /* Print the initial array */
    print_int_array(numbers, num_cells);
    /* Loop that makes a new gen then prints it num_gens number of times */
    for (i = 0; i < num_gens; i++)
    {
        make_next_gen(numbers, numbers2, num_cells);
        print_int_array(numbers, num_cells);
    }

    /* Free the memory */
    free(numbers);
    free(numbers2);
    print_memory_leaks();
    return 0;
}
예제 #5
0
파일: main.c 프로젝트: mykedean/sample-code
//the main program is the boot program
//------------------------------------
//in this case, it simply runs a bunch of tests to make sure the system is working properly
//the test functions exist in the p242p_testHarness file
//the file system functions are all located in the p242p_filesystem.h header
//the disk functions are all located in the p242p_disk.h header
//all prototypes, structs, and definitions are located in the p242pio.h header
int main (int argc, const char * argv[])
{
    int disk, home_directory_inodeID, userFile_inodeID;
    int *freeList, *ilist;
    
    //set testing flag to be set
    testing = 1;
    
    //create a disk
    disk = test_create_disk();
    
    //create freelist & write freelist to disk
    test_create_freeList(disk);
    
    //retrieve freelist
    freeList = test_retrieve_freelist(disk);
    
    //create ilist (creates inodes)
    test_create_ilist(disk, freeList);
    
    //retrieve ilist
    ilist = test_retrieve_ilist(disk);
    
    //--------------------------------Phase 1 complete
    printf("-----\n\n");
    printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
    printf("SYSTEM INITIALIZATION COMPLETED - NOW TESTING FILE DEPENDENT FUNCTIONS \n");
    printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");

    printf("-----\n\n");
    printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
    printf("SYSTEM INITIALIZATION COMPLETED - NOW TESTING FILE/DIRECTORIES \n");
    printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
    
    //create a home directory (creates a file)
    home_directory_inodeID = test_create_directory(disk);

    printf("\nShowing updated free list after inode allocations:\n");
    print_int_array(freeList, FREELIST_SIZE);
    printf("\nShowing updated ilist after directory creation \n(last element is ilist index containing ID of next available inode):\n");
    print_int_array(retrieve_ilist(disk), NUM_INODES+1);
    
    //write the directory
    //read the directory
    
    printf("\nCreating a file within the new home directory:\n");
    //create a file within the new home directory
    userFile_inodeID = test_create_file(disk);
    
    printf("\nShowing updated ilist after directory creation \n(last element is ilist index containing ID of next available inode):\n");
    print_int_array(retrieve_ilist(disk), NUM_INODES+1);
    
    return 0;
}
예제 #6
0
void test_knuth_morris_pratt_table(char test_str[], unsigned int test_len, int table[], int expected_table[])
{
	knuth_morris_pratt_table(test_str, table);

	printf("expected: ");
	print_int_array(expected_table, test_len);

	printf("\nresult:   ");
	print_int_array(table, test_len);
	printf("\n");
}
예제 #7
0
파일: implementation.c 프로젝트: RP-3/EPI
void test(char assertion[], int (*func)(int[],  int), int a[], int size, int expectation[]){

    func(a, size);

    if(int_array_equal(a, expectation, size)){
        printf("%s %s \u2713 %s\n", assertion, KGRN, RESET);
    }else{
        printf("%s %s \u2717 %s\n", assertion, KRED, RESET);
        printf("    Expected :  "); print_int_array(expectation, size);
        printf("    But got  :  "); print_int_array(a, size);
    }
}
예제 #8
0
test_array(const char* description) {
	if (memcmp(sorted_array, random_array2,
				RANDOM_SIZE * sizeof(Item)) == 0)
		printf("%s is sorted\n\n", description);
	else {
		printf("Not sorted:\n");
		print_int_array(random_array2, RANDOM_SIZE,
				description, -1, -1, -1);
		printf("\n\nWhat it should be:\n");
		print_int_array(sorted_array, RANDOM_SIZE,
				"Sorted array", -1, -1, -1);
	}
}
예제 #9
0
int main()
{
	int a[]={1,2,6,2,3,6,3,4,5,9,6,2,8,9,3,5,3,6,3,2};
	count_sort(a,sizeof(a)/sizeof(int));
	print_int_array(a,0,sizeof(a)/sizeof(int)-1);
	return 0;
}
예제 #10
0
void print_int_array( int a[], int n )
{
  if( n >= 0 ) {
    printf( "%d\n", a[n] );
    print_int_array( a, n - 1 );
  }
}
예제 #11
0
int main (void){
	read();
	print_list_graph();
	int *Ts = topo_sort();
	print_int_array(Ts,0,n-1);
	return 0;
}
예제 #12
0
int main () {
	int array[SAMPLE_INT_ARRAY_SIZE];// define an array to be filler
	fillArray(array, SAMPLE_INT_ARRAY_SIZE);// fill the array with random numbers
	print_int_array(array, SAMPLE_INT_ARRAY_SIZE);// print the filled array
	sortArray(array, SAMPLE_INT_ARRAY_SIZE);

return 0;
}
예제 #13
0
int main()
{
	int a[]={1,2,6,2,3,6,3,4,5,9,6,2,8,9,3,5,3,6,3,2};
	int b[sizeof(a)/sizeof(int)];
	merge_sort(a,b,0,sizeof(a)/sizeof(int)-1);
	print_int_array(a,0,sizeof(a)/sizeof(int)-1);
	return 0;
}
예제 #14
0
int main(int argc, const char *argv[])
{
    int a[] = {7,5,6,3,1,6,3,9,2}; 
    char b[] = {"ialljlaslbnvz"};
    print_int_array(a, sizeof(a)/4);
    bubbling(a, 1, sizeof(a)/4, 0, bubbling_int);
    print_int_array(a, sizeof(a)/4);
    bubbling(a, 1, sizeof(a)/4, 1, bubbling_int);
    print_int_array(a, sizeof(a)/4);
     
    printf("%s\n",b);
    bubbling(b, 0, strlen(b), 0, bubbling_char);
    printf("%s\n",b);
    bubbling(b, 0, strlen(b), 1, bubbling_char);
    printf("%s\n",b);
    return 0;
}
예제 #15
0
int main (int argc, char *argv[]) {
	int *numbers = random_int_array(10);
	
	print_int_array(numbers);

	printf("=====================\n");

	gsort(numbers, bubble_sort, int_natural_order);
	print_int_array(numbers);

	printf("=====================\n");

	gsort(numbers, bubble_sort, int_reverse_order);
	print_int_array(numbers);

	return 0;
}
예제 #16
0
int main()
{

	FILE *fp;
	int n, num, pos, *b, *a;
	char c;



	//------- INSERCION DE DATOS EN EL ARREGLO ----------- //
	printf("\nSorting an array... ");
	validate_int_read(&n, "SIZE:");
	b = malloc (sizeof(int) * n);
	read_rand_array(b, n);
	a = b;

	// for (i = 0; i < n; i++)
	// 	scanf("%d", &a[i]);

	// -------- IMPRESION EN PANTALLA DEL ARREGLO DE DATOS DESORDENADO ---- //
	printf("\nBEFORE:\n");
	print_int_array(a, n);


	// ------ PETICION AL USUARIO DEL METODO A UTILIZAR PARA ORDENAR ------- //
	sort_array(a, n);

	// -------- IMPRESION EN PANTALLA DEL ARREGLO DE DATOS DESORDENADO ---- //
	printf("\nAFTER:\n");
	print_int_array(a, n);

	// -------- BUSQUEDA BINARIA //
	printf("\n\nSearching in the array... ");
	validate_int_read(&num, "NUMBER:");

	pos = search_in_array(a, n, num);


	printf("\n\nWriting in file... ");
	write_results_file(fp, a, b, num, pos, n);

	// fclose(fp);

	return 0;
}
void test_strong_component(Graph *g) {
    int *group = (int *)malloc(sizeof(int) * g->vertexNum);
    if(group == NULL)
        return;
    strong_component(g, group);
    printf("group info is: \n");
    print_int_array(group, g->vertexNum);
    printf("\n");
}
예제 #18
0
파일: heap.c 프로젝트: njdragonfly/CLRS
int main()
{
	int h[]={21,12,33,34,54,63,77};

	heap_sort(h,sizeof(h)/sizeof(int));
	print_int_array(h,0,sizeof(h)/sizeof(int)-1);

	return 0;

}
void test_bfs(Graph *g) {
    int *dist = (int *)malloc(g->vertexNum * sizeof(int));
    int v, w;
    printf("Test BFS, Graph g has %d nodes\n", g->vertexNum);
    printf("Input two node: ");
    scanf("%d %d", &v, &w);
    bfs(g, v, dist);
    print_int_array(dist, g->vertexNum);
    printf("\n");
    printf("The shortest dist from node %d to node %d is %d\n", v, w, dist[w]);
}
예제 #20
0
test_sort(void sort(Item*, int), char* description) {
	for(int i = 8; i < 256; i++) {
		int* a = malloc(i * sizeof(Item));
		int* b = malloc(i * sizeof(Item));
		fill_random_array(a, i, i);
		memcpy(b, a, i * sizeof(Item));
		qsort((void*)a, i, sizeof(Item), compare_ints);
		sort(b, i);
		if (memcmp(a, b, i * sizeof(Item)) != 0) {
			printf("%s is not sorted (size == %d):\n", 
					description, i);
			print_int_array(b, i, description, -1, -1, -1);
			printf("\n\nWhat it should be:\n");
			print_int_array(a, i, "Sorted array", -1, -1, -1);
			exit(-1);
		}
		free(a); free(b);
	}
	printf("Testing of %s complete\n", description);
}
예제 #21
0
파일: m.c 프로젝트: mandeep-sinng/misc
void sort(int *array, int size) {
    int *i, *j, k;
    for (i = array; i < array+size; ++i) {
        print_int_array("Pass", array, size);
        for (j = i + 1; j < array+size; ++j) {
            if (*i > *j) {
                k = *i;
                *i = *j;
                *j = k;
            }
        }
    }
}
예제 #22
0
파일: clab2.c 프로젝트: kevinschaich/cs3410
int main(int argc, char *argv[])
{
    int len = 5;

    // seed the random number generator
    srand(time(NULL));

    int* arrayA = rand_array(len);
    print_int_array(arrayA, len);
    int* arrayB = rand_array(len);
    print_int_array(arrayB, len);

    complex_number* complexArray = initialize_complex_array(arrayA, arrayB, len);
    float* magnitudeArray = calculate_magnitudes(complexArray, len);
    print_float_array(magnitudeArray, len);

    // free memory
    free(arrayA);
    free(arrayB);
    free(complexArray);
    free(magnitudeArray);
}
예제 #23
0
파일: test.c 프로젝트: Rad0x6f/kpro9
void print_xcon(struct xcon *xc)
{
   printf("agent_type=%d\n", xc->agent_type);
   printf("agent_id=%lu\n", xc->agent_id);
   printf("features=0x%x\n", xc->features);
   print_int_array("pres_ctx", xc->pres_ctx, sizeof(xc->pres_ctx)/sizeof(int));
   print_octet_array("common_ref", xc->common_ref, sizeof(xc->common_ref)/sizeof(OCTET));
   printf("name=%s\n", xc->name);
   print_sap("a_xsap=", &xc->a_xsap);
   print_sap("b_xsap=", &xc->b_xsap);
   printf("result_source=%d\n", xc->result_source);
   printf("diagnostic=%d\n", xc->diagnostic);
}
예제 #24
0
파일: m.c 프로젝트: mandeep-sinng/misc
int main(int argc, char **argv) {
    char name[256];
    int array[9] = {5,1,9,2,8,3,7,4,6};
    char *p;

    printf("Hello World!\n");
    printf("Tell me your name: ");
    fgets(name, 256, stdin);

    p = name + strlen(name) - 1;
    while (*p == '\r' || *p == '\n') {
        *p = 0;
        --p;
    }

    printf("Welcome \"%s\"...to the world of C!", name);

    print_int_array("Before", array, 9);
    sort(array, 9);
    print_int_array("After", array, 9);

    return 0;
}
예제 #25
0
파일: at3.c 프로젝트: bwolfson978/CS2303
int main() {
  int i; // Loop counter
  int a[SAMPLE_INT_ARRAY_SIZE]; // Sample array for demonstration
 
  //change seed of random integers once per run of the program
  srand(time(NULL));
 
  //fill array with random integers
  populate_random_int_array(a, SAMPLE_INT_ARRAY_SIZE);
  
  //print the array of random ints;
  printf("Here is the array of random integers:\n");
  print_int_array(a, SAMPLE_INT_ARRAY_SIZE);

  //sort the array
  bubble_sort(a, SAMPLE_INT_ARRAY_SIZE);

  //print the sorted array
  printf("Here is the sorted array:\n");
  print_int_array(a, SAMPLE_INT_ARRAY_SIZE);

  return 0;
}
예제 #26
0
int main() {
	const int ARRAY_SIZE = 4;
	int int_array[ARRAY_SIZE] = {5, 111, -86, 84};
	qsort(int_array, ARRAY_SIZE, sizeof(int), compare_func);
	print_int_array(int_array, ARRAY_SIZE);

	char char_array[ARRAY_SIZE] = {'z', 'y', 'c', 't'};
	qsort(char_array, ARRAY_SIZE, sizeof(char), compare_char);
	print_char_array(char_array, ARRAY_SIZE);

	float float_array[ARRAY_SIZE] = {1.2, 99.6, 3.14, 0.4751};
	qsort(float_array, ARRAY_SIZE, sizeof(float), compare_float);
	print_float_array(float_array, ARRAY_SIZE);

	return 0;
}
예제 #27
0
int main()
{
  unsigned int v0[10];
  int v1[5] = { 1, 2, 3, 4, 5 };
  long double v2[10] = { 1.2, 2.3 };
  double m0[2][3] = { {1.1, 1.2, 1.3}, {2.2, 2.3, 2.4} };

  printf( "%d\n", v1[2] );
  printf( "%d\n", *(v1 + 2) );

  printf( "%lf\n", v2[5] );

  print_int_array( v1, 4 );

  return 0;
}
예제 #28
0
파일: lab5.c 프로젝트: SahinEgilmez/C_Works
int main()
{
	int number;
	int x[5];
	int p_arr[5];
	BOOL a,b,c;
	
	a=is_prime(number);
	b=is_prime(number);
	c=is_prime(number);
	if(a==TRUE)
		printf("asal");
	assign_numbers_to_array(p_arr,5,is_odd);
	print_int_array(p_arr,5);

	return 0;

}
void typeArrayKlass::oop_print_on(oop obj, outputStream* st) {
  arrayKlass::oop_print_on(obj, st);
  typeArrayOop ta = typeArrayOop(obj);
  int print_len = MIN2((intx) ta->length(), MaxElementPrintSize);
  switch (element_type()) {
    case T_BOOLEAN: print_boolean_array(ta, print_len, st); break;
    case T_CHAR:    print_char_array(ta, print_len, st);    break;
    case T_FLOAT:   print_float_array(ta, print_len, st);   break;
    case T_DOUBLE:  print_double_array(ta, print_len, st);  break;
    case T_BYTE:    print_byte_array(ta, print_len, st);    break;
    case T_SHORT:   print_short_array(ta, print_len, st);   break;
    case T_INT:     print_int_array(ta, print_len, st);     break;
    case T_LONG:    print_long_array(ta, print_len, st);    break;
    default: ShouldNotReachHere();
  }
  int remaining = ta->length() - print_len;
  if (remaining > 0) {
    tty->print_cr(" - <%d more elements, increase MaxElementPrintSize to print>", remaining);
  }
}
예제 #30
0
int main(int argc, char *argv[]) {
	//int c[] = {1,2,3,4,5,6};
	srand(time(NULL));
	int random_array[rand()%11];
	int array_size = sizeof(random_array)/sizeof(int);
	printf("%i, %i\n", sizeof(random_array), sizeof(int));
	fill_int_array(random_array);
	printf("The length of the array is %i\n", array_size);
	print_int_array(random_array);
	
	//int current;
	//int close = 1;
	//char response[3];
	/*
	printf("Please enter a non-negative integer value\n");
	scanf("%i", &current);
	printf("The value at index %i is %i\n",current, c[current]);
	while (close == 1) {
		printf("Enter 'n' for next and 'p' for previous or 'x' to close: \n" );
		scanf("%s", response);
		switch (response[0]) {
			case 'p':
				previous(&current);
				printf("The value at index %i is %i\n",current, c[current]);
				continue;
			case 'n':
				next(&current);
				printf("The value at index %i is %i\n",current, c[current]);
				continue;
			case 'x':
				close = 0;
				continue;	
			default:
				printf("You didn't put a recognised character.");
				break;
		}
	}*/
	return 0;
	
}