//////////////////////////////// // // prog_practice_7 project // // 9/21/22 tj // // practice programming with arrays // ////////////////////////////// #include "mbed.h" #include void print_ary(const int the_ary[], int n); void load_ary(int an_ary[], int n); void load_ary2(int an_ary[], int n); void copy_ary(int src_ary[], int dest_ary[], int n); void swap_ary(int the_ary[], int n); int main(void){ setbuf(stdout, NULL); // fix buffer problem // splash - no function to save time printf("\n\nArray program\n\n"); int ary1[10]; int ary2[10] = {5,7,9,1,3,6,8,2,4,0}; // print garbage print_ary(ary1, 10); // print initialized array print_ary(ary2, 10); // print some random locations // note last value is actuall out of range printf("%i %i %i\n", ary2[3], ary2[6], ary2[10]); // set some random locations ary2[5] = 99; ary2[7] = 66; print_ary(ary2, 10); // load values into an array load_ary(ary1, 10); print_ary(ary1, 10); // load values into an array load_ary2(ary1, 10); print_ary(ary1, 10); // copy the array copy_ary(ary1, ary2, 10); print_ary(ary1, 10); print_ary(ary2, 10); // do swap on an array swap_ary(ary1, 10); print_ary(ary1, 10); return 0; }// end main void print_ary(const int the_ary[], int n){ // use const to indicate it is not your intention to modify the array int i; for(i = 0; i < n; i++) printf("%i ", the_ary[i]); printf("\n"); return; }// end print_ary void load_ary(int an_ary[], int n){ int i; for(i = 0; i < n; i++){ printf("enter value %i for the array: ", i); scanf("%i", &an_ary[i]); } return; }// end load_ary void load_ary2(int an_ary[], int n){ int i; printf("enter value %i values for the array: ", n); for(i = 0; i < n; i++){ scanf("%i", &an_ary[i]); } return; }// end load_ary void copy_ary(int src_ary[], int dest_ary[], int n){ int i; for(i = 0; i < n; i++){ dest_ary[i] = src_ary[i]; } return; }// end copy_ary void swap_ary(int the_ary[], int n){ int i; int tmp_ary[n]; copy_ary(the_ary, tmp_ary, n); for(i = 0; i < n; i++) the_ary[i] = tmp_ary[(n - 1) - i]; return; }// end swap_ary