return matrix on C

Viewed 1551

Here is my code below.

#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

void rot(int angle);
static double R[3][3]={0};

int main(void) {
    int angle = 30;
    rot(angle);
    int i, j = 0;

   for (i = 0; i < 3;i++) {
      for (j = 0; j < 3; j++) {
        printf("%lf\n", R[i][j]);
    }
}
return 0;
}

void rot(int angle) {
    double cang = cos(angle*M_PI / 180);
    double sang = sin(angle*M_PI / 180);

    R[0][0] = cang;
    R[1][1] = cang;
    R[1][0] = -sang;
    R[0][1] = sang;
}

For now, function rot do not return any value itself. But since R is static double, I was able to print out the R changed by rot function. I want to change function rot to return R[3][3](two dimension array). So I want to use rot function on main like

double R1=rot(30);
double R2=rot(60);

is there any way to make it possible?

2 Answers
Related