- Pointer Exercise Given The Following C Program Int Main Int Index Double Data 3 Getdata Data 0 Data 1 Dat 1 (71.12 KiB) Viewed 55 times
Pointer Exercise Given the following C program: int main() ( int index; double data[3]; GetData(&data[0], &data[1], &dat
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Pointer Exercise Given the following C program: int main() ( int index; double data[3]; GetData(&data[0], &data[1], &dat
Pointer Exercise Given the following C program: int main() ( int index; double data[3]; GetData(&data[0], &data[1], &data[2]); printf("Index Data\n"); for (index=0; index < 3; index++) { } printf("%5d %8.31f\n", index, data[index]); 0 1 2 getch(); return 0; } The main function creates a double array with 3 elements and then passes all three elements (individually) to the GetData function. The main then prints the three values from the data array along with their element numbers. Complete the program by creating the function GetData that works as follows: 1. The function must assign the value 7.5 to element 0 of the data array. 2. The function must ask the user what value to assign to element 1 of the data array and input that value from the user. Make sure that you use the pointer representing the array element directly in your scanf (that is, you cannot input into a simple variable and then assign to the element). 3. The function must add the value from element 0 and element 1 of the array and assign the sum to element 2 of the data array (make sure you are retrieving the value from element 0 and not just hardcoding the 7.5). An execution of the program might look as follows: What value would you like to assign to element 1? 10.5 Index Data 7.500 10.500 18.000