i have menu user has enter number following case manipulation array. menu has done in order. example user must first set size of array , pass elements array in separate module.
- 1- enter size of array 2- enter array elements 3- sort array 4- find number within array 5- print array
6-reverse print array 7- quit
please enter choice: 3 array not initialized yet!
this code far. having trouble on initializing array , entering elements. once done sure can rest:
int sizearray(); int *enterelements(int size, int *anarray); int main(){ int choice; int tempsize; int marray[100]; //initialize array do{ printf("1 - enter size of array\n"); printf("2 - enter array elements\n"); printf("3 - sort array\n"); printf("4 - find number within array\n"); printf("5 - print array\n"); printf("6 - reverse print array\n"); printf("7 - quit\n"); printf("\n"); printf("please enter choice: "); scanf("%d", &choice); switch (choice){ case 1: int tempsize = sizearray(); case 2: if (tempsize != 0){ enterelements(tempsize); } else{ printf("you should first set size of array\n"); } default: if (choice < 1 || choice > 7) printf("invalid choice please choose again\n"); }; } while (choice != 7); } int sizearray(){ int size = 0; printf("what size of array(1-20)? "); scanf_s("%d", size); if (size > 20 || size < 1){ printf("array size should between 1 , 20 "); } return size; } int *enterelements(int size){ int = 0; (i = 0; < size; i++) { printf("enter array element %d :", i); scanf_s("%d", &anarray[i]); } }
i think enterelements function should this:
void enterelements(int *anarray, int size) { //your code here } and call function as:
enterelements(marray, tempsize); also within case shouldn't declare new int tempsize variable, overrides 1 before loop.
Comments
Post a Comment