fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define _USE_MATH_DEFINES
  3. #include <math.h>
  4. #include <stdio.h>
  5.  
  6. #define DIV 720
  7.  
  8. int main()
  9. {
  10. double s1, s2, s3, h, rad;
  11. int m, n, x;
  12.  
  13. while (1) {
  14. printf("m n=");
  15. scanf("%d%d", &m, &n);
  16. if (m == 0 || n == 0) {
  17. break;
  18. }
  19. s1 = s2 = s3 = 0.0;
  20. h = 2.0 / DIV;
  21. for (x = 0; x < DIV; x++) {
  22. rad = 2 * M_PI * x / DIV;
  23. s1 += sin(n * rad) * sin(m * rad) * h;
  24. s2 += cos(n * rad) * cos(m * rad) * h;
  25. s3 += sin(n * rad) * cos(m * rad) * h;
  26. }
  27. printf("\nm=%d n=%d\n", m, n);
  28. printf("S1=%f\n", s1);
  29. printf("S2=%f\n", s2);
  30. printf("S3=%f\n", s3);
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.02s 1724KB
stdin
1 1
2 2
1 2
0 0
stdout
m n=
m=1 n=1
S1=1.000000
S2=1.000000
S3=-0.000000
m n=
m=2 n=2
S1=1.000000
S2=1.000000
S3=-0.000000
m n=
m=1 n=2
S1=0.000000
S2=-0.000000
S3=0.000000
m n=