//Program begin int main(void) { //Set seed for rand() srand(time(NULL)); //Local Variables int userSize; int array[MAX][MAX]; printf("\n" "Enter the size of the array: "); scanf("%d", &userSize); while(check_error(userSize) != 1) { printf("Invalid input enter the size of the array again: "); scanf("%d", &userSize); } initialize_2Darray(array, userSize); printf("\n" "Input Array\n"); print_2Darray(array, userSize); printf("\n" "The smallest number in the array is %d\n\n", smallest_number(array, userSize)); return 0; }
int main(void) { int array[] = {2, -8, 5, 3, -1, 9, 2, 7}; int size = 8; int smallest = smallest_number(array, size); printf("%d\n", smallest); return 0; }
int menu_body(char ch,int choice) { static int flag; static int number; static int sorted=0; static int mem=0; int count,status,key,result; switch (ch) { case ESC: { clrscr(); flag=1; } break; case ENTER: { switch(choice) { /*Enter Data*/ case 0: clrscr(); gotoxy(0,0); /*Please Add your function here*/ puts("Enter Number of Elements"); fflush(stdout); scanf("%d",&number); ptr_data=(int*)malloc(number*sizeof(int)); if(ptr_data==NULL) { puts("No Enough Memorey"); break; } else { puts("Enter the elements which to be processed: "); for(count=0; count<number; count++) { printf("Enter number %d of %d\n",count+1,number); fflush(stdout); scanf("%d",&ptr_data[count]); } } mem=1; sorted=0; puts("Enter any key to back to menu"); system("pause"); break; /*Linear Search*/ case 1: clrscr(); gotoxy(0,0); /*Please Add your function here*/ if(mem==1 && sorted==1 ) { puts("Linear Search\n\n"); puts("Enter the Number you are searching for"); fflush(stdout); scanf("%d",&key); status=linear_search(ptr_data, number, key); (status==TRUE)? (puts("The key has been found")): (puts("The key is not presented in the list")); } else { puts("You didn't enter any data or the data unsorted\n"); } puts("Enter any key to back to menu"); system("pause"); break; /*Binary Search*/ case 2: clrscr(); gotoxy(0,0); /*Please Add your function here*/ if(mem==1 && sorted==1) { puts("Binary Search\n\n"); puts("Enter the Number you are searching for"); fflush(stdout); scanf("%d",&key); status=binary_search(ptr_data, number, key, &result); (status==TRUE)? (printf("The key has been found at loc=%d\n\n",result)): (puts("The key is not presented in the list")); } else { puts("You didn't enter any data or the data unsorted\n"); } puts("Enter any key to back to menu"); system("pause"); break; /*Find Biggest*/ case 3: clrscr(); gotoxy(0,0); /*Please Add your function here*/ if(mem==1) { puts("Biggest\n\n"); status=biggest_number(ptr_data, number); printf("The biggest number is %d\n\n", status); } else { puts("You didn't enter any data\n"); } puts("Enter any key to back to menu"); system("pause"); break; /*Find Smallest*/ case 4: clrscr(); gotoxy(0,0); /*Please Add your function here*/ if(mem==1) { puts("Smallest\n\n"); status=smallest_number(ptr_data, number); printf("The smallest number is %d\n\n", status); } else { puts("You didn't enter any data\n"); } puts("Enter any key to back to menu"); system("pause"); break; /*Find 2nd Biggest*/ case 5: clrscr(); gotoxy(0,0); /*Please Add your function here*/ if(mem==1) { puts("The second biggest\n\n"); status=sec_biggest_number(ptr_data, number); printf("The second biggest number is %d\n\n", status); } else { puts("You didn't enter any data\n"); } puts("Enter any key to back to menu"); system("pause"); break; /*Find 2nd Smallest*/ case 6: clrscr(); gotoxy(0,0); /*Please Add your function here*/ if(mem==1) { puts("The second Smallest\n\n"); status=sec_smallest_number(ptr_data, number); printf("The Second smallest number is %d\n\n", status); } else { puts("You didn't enter any data\n"); } puts("Enter any key to back to menu"); system("pause"); break; /*Selection Sort*/ case 7: clrscr(); gotoxy(0,0); /*Please Add your function here*/ if(mem==1) { puts("The Selection Sort\n\n"); selection_sort(ptr_data, number); print_array(ptr_data, number); sorted=1; } else { puts("You didn't enter any data\n"); } puts("Enter any key to back to menu"); system("pause"); break; /*bubble_sort Sort*/ case 8: clrscr(); gotoxy(0,0); /*Please Add your function here*/ if(mem==1) { puts("The bubble_sort Sort\n\n"); puts("Enter 1 for ascending order"); puts("Enter 2 for descending order"); fflush(stdout); scanf("%d",&key); if (key==1)bubble_sort(ptr_data, number,ascending); else bubble_sort(ptr_data, number,descending); print_array(ptr_data, number); sorted=1; } else { puts("You didn't enter any data\n"); } puts("Enter any key to back to menu"); system("pause"); break; /*insertion_sort */ case 9: clrscr(); gotoxy(0,0); /*Please Add your function here*/ if(mem==1) { puts("The bubble_sort Sort\n\n"); insertion_sort(ptr_data, number); print_array(ptr_data, number); sorted=1; } else { puts("You didn't enter any data\n"); } puts("Enter any key to back to menu"); system("pause"); break; case 10: clrscr(); gotoxy(0,0); if(mem==1) { free(ptr_data); puts("The input data has been removed\n\n"); mem=0; } else { puts("You didn't enter any data\n"); } puts("Enter any key to back to menu"); system("pause"); break; case 11: flag=1; break; } } } return(flag); }