Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void show_menu();
- int *read_array(int *);
- void print_array(int *, int);
- int biggest_odd(int *, int);
- int smallest_even(int *, int);
- int main()
- {
- int size;
- int *arr;
- while (1)
- {
- show_menu();
- int choice;
- scanf("%d", &choice);
- if (choice == 1)
- {
- arr = read_array(&size);
- }
- else if (choice == 2)
- {
- print_array(arr, size);
- }
- else if (choice == 3)
- {
- printf("The biggest odd number is: %d\n", biggest_odd(arr, size));
- }
- else if (choice == 4)
- {
- printf("The smallest even number is: %d\n", smallest_even(arr, size));
- }
- else if (choice == 5)
- {
- return 0;
- }
- else
- {
- printf("Invalid input!\n\n");
- }
- }
- return 0;
- }
- void show_menu()
- {
- printf("\n1. Read an array\n");
- printf("2. Print array\n");
- printf("3. Get largest odd number\n");
- printf("4. Get smallest even number\n");
- printf("5. Exit\n");
- printf("Choose your option: ");
- }
- int *read_array(int *size)
- {
- *size = 1;
- int *arr;
- int arr_size = 10;
- char buffer;
- arr = (int *)malloc(arr_size * sizeof(int));
- printf("Enter value of element at index %d: ", *size - 1);
- while (scanf("%d", &arr[*size - 1]) == 1)
- {
- *size = *size + 1;
- if (*size > arr_size)
- {
- arr_size += 10;
- arr = realloc(arr, arr_size * sizeof(int));
- }
- printf("Enter value of element at index %d: ", *size - 1);
- }
- return arr;
- }
- void print_array(int *array, int size)
- {
- printf("[");
- for (int i = 0; i < size; i++)
- {
- printf("%d", array[i]);
- if (i != sizeof(array) / sizeof(array[0]) - 1)
- printf(", ");
- }
- printf("]\n\n");
- }
- int biggest_odd(int *arr, int size)
- {
- // TODO
- return -1;
- }
- int smallest_even(int *arr, int size)
- {
- // TODO
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement