コード例 #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
コード例 #2
0
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
ファイル: 1dca_pointer.c プロジェクト: arcticmatt/CS11-C
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
ファイル: count_sort.c プロジェクト: njdragonfly/CLRS
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
ファイル: prog07.c プロジェクト: arthurtumanyan/notes-on-c
void print_int_array( int a[], int n )
{
  if( n >= 0 ) {
    printf( "%d\n", a[n] );
    print_int_array( a, n - 1 );
  }
}
コード例 #11
0
ファイル: topo-sort.c プロジェクト: hunglvosu/algorithm
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
ファイル: merge_sort.c プロジェクト: njdragonfly/CLRS
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
ファイル: ex18.c プロジェクト: nulpunkt/learn-c-the-hard-way
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
ファイル: sorting.c プロジェクト: intfrr/c-functions
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;
}
コード例 #17
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;

}
コード例 #19
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
ファイル: prog07.c プロジェクト: arthurtumanyan/notes-on-c
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;

}
コード例 #29
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;
	
}