|
|
Subject:
C language programming exercise I need answer
Category: Computers > Programming Asked by: lantern81-ga List Price: $10.00 |
Posted:
19 Nov 2002 21:14 PST
Expires: 19 Dec 2002 21:14 PST Question ID: 111069 |
I need the exact c language code for the following. Write a program that initializes an array of double and then copies the contents of the array into two other arrays.( All three arrays should be declared in the main program.) To make the first copy, use a function with array notation. To make the second copy, use a function with pointer notation and pointer incrementing. Have each function take as arguments, the name of the target array, and the number of elements to be copied. That is the function calls would look like this, given the following declarations: double source[5]= {1.1, 2.2, 3.3, 4.4, 5.5,}; double target1[5]; double target2[5}; copy_arr(source, target1, 5); copy_ptr(source, target1, 5); |
|
Subject:
Re: C language programming exercise I need answer
Answered By: rbnn-ga on 19 Nov 2002 23:47 PST Rated: |
Thank you for the question. I have implemented the required specification and included the file below. Here is the script: % gcc copy.c % ./a.exe Success Here is the file copy.c . I have also placed a copy of this file at: http://www.rbnn.com/google/copy.c since sometimes program codes do not render correctly. As always, if you would like additional features or have any questions, please solicit these using the "request clarification" button in your browser before rating the answer. -----------INCLUDED FILE copy.c--------- #include <stdlib.h> void copy_arr(double source[], double target[], int len){ int i; for (i=0;i<len;++i) target[i]=source[i]; } void copy_ptr(double * source, double * target, int len){ int i; for (i=0;i<len;++i) *target++=*source++; } int main(){ double source[5]= {1.1, 2.2, 3.3, 4.4, 5.5,}; double target1[5]; double target2[5]; int i; int error=0; copy_arr(source, target1, 5); copy_ptr(source, target2, 5); for (i=0;i<5;++i) if (source[i]!=target1[i]|| source[i]!=target2[i]){ printf("Error at: %d\n",i); error=1; } if (error) printf("Failure\n"); else printf("Success\n"); } |
lantern81-ga rated this answer: |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |