I am trying to write a program that will compute an angle and magnitude of a given complex number. I have therefore declared an array of 2 floats in which [0] stores the real part and [1] the imaginary part. My code looks as follows:
Code:
#include <stdio.h>
#include <math.h>
float magnitude(float c[]);
void arc(float c, int *arcn);
int main()
{
float complex[2];
float owned;
printf("Enter real part > ");
scanf("%f", &complex[0]);
printf("Enter imaginary part > ");
scanf("%f", &complex[1]);
printf("Magnitude: %f", magnitude(complex));
arc(complex, &owned);
printf("Angle: %f", owned);
}
float magnitude(float c[])
{
float temp;
temp = sqrt(c[0]*c[0] + c[1]*c[1]);
return temp;
}
void arc(float c[], float *arcn)
{
*arcn = atan(c[1]/c[0]);
}
However I am getting an error:
Code:
main.c(19) : error C2440: 'function' : cannot convert from 'float [2]' to 'float'
What is wrong with the program? Please help.
I know I could use a return statement in the second function, but I do not want to. The whole purpose of this program is to excercise functions which return a value, and which manupulate values passed by a pointer.