168k views
5 votes
Write a C program to create two user-defined functions; first function name as Input() and second function Print(). Call Input() function from main function and Input() function will take 6 integer as an array input from user. Next pass the array to Print() function, then print all odd index elements inside Print() function.

Example: Input from user in input() function : { 1, 4, 7, 23, 35, 15} then output printed by the Print() function will be { 4, 23, 15}

1 Answer

4 votes

Final answer:

The question involves writing a C program with two functions, Input() and Print(), to collect an array of integers and print elements at odd indices, respectively. A sample code is provided.

Step-by-step explanation:

The student is asking for a C program that includes two user-defined functions: Input() and Print(). The main function calls Input(), which takes an array of 6 integers from the user. The array is then passed to Print(), where all the elements at odd indices are printed.



Example C Program

Here is an example of how this can be done:

#include

void Input(int arr[]);
void Print(int arr[]);

int main() {
int array[6];
Input(array);
Print(array);
return 0;
}

void Input(int arr[]) {
for (int i = 0; i < 6; i++) {
scanf("%d", &arr[i]);
}
}

void Print(int arr[]) {
for (int i = 1; i < 6; i += 2) {
printf("%d ", arr[i]);
}
printf("\\");
}

In this program, the Input() function collects 6 integers from the user and stores them in an array. The Print() function then iterates through the array, printing the elements located at odd indices.

User Arturo Mejia
by
8.0k points