Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a piece of C code with a function called doublearray , which takes an arra

ID: 3758579 • Letter: W

Question

Write a piece of C code with a function called doublearray, which takes an array of 10 elements as input and doubles each element upon return.

i.e. #include <stdio.h>

void doublearray(float *a)

{

/* write your code here) */

}

int main()

{

int i;

float b[10]={1.0 ,2.0 ,3.0 ,4.0 ,5.0 ,6.0, 7.0, 8.0, 9.0,10.0};

doublearray(b);

for (i=0;i<10;i++)

printf("%f ", b[i])

return 0;

}

So that it returns:

2.000000

4.000000

6.000000

8.000000

10.000000

12.000000

14.000000

16.000000

18.000000

20.000000

Make sure that you attach example runs showing the results from the computer.

I'm confused as to what exactly this question is asking me to do and I'm not sure what code it wants me to write.

i.e. #include <stdio.h>

void doublearray(float *a)

{

/* write your code here) */

}

int main()

{

int i;

float b[10]={1.0 ,2.0 ,3.0 ,4.0 ,5.0 ,6.0, 7.0, 8.0, 9.0,10.0};

doublearray(b);

for (i=0;i<10;i++)

printf("%f ", b[i])

return 0;

}

So that it returns:

2.000000

4.000000

6.000000

8.000000

10.000000

12.000000

14.000000

16.000000

18.000000

20.000000

Make sure that you attach example runs showing the results from the computer.

I'm confused as to what exactly this question is asking me to do and I'm not sure what code it wants me to write.

Explanation / Answer

#include <stdio.h>
void doublearray(float *a)
{
   int i;
   for (i=0;i<10;i++)
       a[i] *= 2;
}
int main()
{
int i;
float b[10]={1.0 ,2.0 ,3.0 ,4.0 ,5.0 ,6.0, 7.0, 8.0, 9.0,10.0};
doublearray(b);
for (i=0;i<10;i++)
printf("%f ", b[i]);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote