Question: Hello! Programming in C. I have an inputfile with 2 columns (name them: a,b) Now, I have write the following program and I have to
Hello!
Programming in C.
I have an inputfile with 2 columns (name them: a,b) Now, I have write the following program and I have to use a subroutine.
#include ....
float subroutine (???);
int i, number_of_data; main() {FILE *inputfile;
float a[100], b[100], p1, p2, d;
i=1;
scanf("%f %f %f", &p1, &p2, &d); while( fscanf (inputfile, " %f " ,&a[i], &b[i] ) !=EOF) { printf (%f %f ", a[i], b[i] ); i=i+1; } number_of_data= i - 1;
for (i=1; i <=number_of_data; ++i) { V=(Va-Vb) //from subroutine }
float subroutine(??)
??
I want to return from the subroutine to the main , function Vr=( p1 / ) ((1 / r)+(2L / r1)+ (2*L2/ r2)+......2*Ln / rn) where L=(p2+p1)/ (p1-p2) and rn=sqrt( r2 + (2*n*dist)), where p1, p2 and dist are input from the user (scanf) and r is data from array a and data from array b, so inside the subroutine I will have a loop, once for data in a and one in b. As a return I want the Va and Vb, so in the main () I will do some extra calculation with those (V= Va-Vb).
I have no idea how to write the subroutine and return to main the right function and then how to use them in the main().
Please, some help??
Thank you in advance!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
