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

Write a program that declares three one-dimensional arrays named current, resist

ID: 3933503 • Letter: W

Question

Write a program that declares three one-dimensional arrays named current, resistance, and voltage.

Each array should be declared in main() and be capable of holding 10 double-precision numbers.

The numbers to be stored in current are 10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, and 3.98.

The numbers to be stored in resistance are 4, 8.5, 6, 7.35, 9, 15.3, 3, 5.4, 2.9, and 4.8. Have your program pass

these three arrays to a function called calcVolts(), which calculates the elements in the voltage array as

the product of the equivalent elements in the current and resistance arrays: for example, voltage[1] = current[1] * resistance[1].

After calcVolts() has put values in the voltage array, display the values in the array from within main(). Write the calcVolts() function by using pointers.

Explanation / Answer

#include <stdio.h>

void calcvolts(double *current,double *resistance,double *voltage)// to compute voltage values
{
    int i;
    for(i=0;i<10;i++)
    *(voltage+i)=*(current+i)+*(resistance+i);
}
int main()
{
double current[]={10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15,3.98};
double resistance[]={4, 8.5, 6, 7.35, 9, 15.3, 3, 5.4, 2.9, 4.8},voltage[10];
    int i;
    calcvolts(current,resistance,voltage);//function call passing the arrays
    printf("content of voltage array is ");
    for(i=0;i<10;i++)
    printf(" voltage[%d]=%lf ",i,voltage[i]);
  
    return 0;
}

output:

voltage[9]=4621132318645797519                                                                                                

sh-4.3$ gcc -o main *.c                                                                                                        

sh-4.3$ main                                                                                                                   

content of voltage array is                                                                                                    

voltage[0]=14.620000                                                                                                          

voltage[1]=23.390000                                                                                                          

voltage[2]=19.210000                                                                                                          

voltage[3]=23.900000                                                                                                          

voltage[4]=27.620000                                                                                                          

voltage[5]=24.770000                                                                                                          

voltage[6]=9.580000                                                                                                           

voltage[7]=23.720000                                                                                                          

voltage[8]=15.050000                                                                                                          

voltage[9]=8.780000                                                                                                           

sh-4.3$

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