user-0 提问: 运行没结果

回复:
user: user-1
content: #include <stdio.h> #include <stdlib.h> #include <math.h>  #define pi 3.1415926535  double sinx(double a);  int main() {     double a;     scanf("%lf", &a);      printf("a = %lf\n", a);     printf("角a（弧度制）的正弦值为：%lf \n",sinx(a));     printf("角a（弧度制）的余弦值为：%lf \n",sqrt(1 - sinx(a)*sinx(a)));     printf("角a（弧度制）的正切值为：%lf \n",sinx(a) / sqrt(1 - sinx(a)*sinx(a)));      return 0; }  double sinx(double a) {     int i;     double angle[] = {pi/4,pi/8,pi/16,         pi/32,pi/64,pi/128,         pi/256,pi/512,pi/1024,         pi/2048,pi/4096,pi/8192,pi/16384     };      double tan1[]={1,0.4142135623731,0.19891236737966,         0.098491403357164,0.049126849769467,         0.024548622108925,0.012272462379566,         0.0061360001576234,0.0030679712014227,         0.0015339819910887,0.00076699054434309,         0.00038349521577144,0.00019174760083571};      if(a <= (pi/16384)) {         return a; //因为a的值太小，sin a 约等于 a     }else{          //开始 CORDIC 算法          int negitive = a < 0; // sin(-a) = -sin(a)          double x = 10;          double y = 0;          double theta = 0;          for(i = 0;i < 13;i ++){ //开始迭代              double orix,oriy;              while(theta < a){ //当前角度小于a                  orix = x;                  oriy = y;                  //坐标旋转                  x = orix - tan1[i] * oriy;                  y = tan1[i] * orix + oriy;                  theta += angle[i];              }              if(theta == a){                  if(negitive){                      return -(y/sqrt((x*x+y*y)));                  }else{                      return (y/sqrt((x*x+y*y)));                  }              }else{                  //旋转的弧度超过了a，退回原来增加的角度，同时进入下一次迭代                  theta -= angle[i];                  x = orix;                  y = oriy;              }          }          if(negitive){              return -(y/sqrt((x*x+y*y)));          }else{              return (y/sqrt((x*x+y*y)));          }      }  }  供参考～  代码有问题，函数内定义函数了。你确定是抄别人可以运行的代码～？

user: user-0
content: 引用 5 楼 自信男孩的回复:#include <stdio.h> #include <stdlib.h> #include <math.h>  #define pi 3.1415926535  double sinx(double a);  int main() {     double a;     scanf("%lf", &a);      printf("a = %lf\n", a);     printf("角a（弧度制）的正弦值为：%lf \n",sinx(a));     printf("角a（弧度制）的余弦值为：%lf \n",sqrt(1 - sinx(a)*sinx(a)));     printf("角a（弧度制）的正切值为：%lf \n",sinx(a) / sqrt(1 - sinx(a)*sinx(a)));      return 0; }  double sinx(double a) {     int i;     double angle[] = {pi/4,pi/8,pi/16,         pi/32,pi/64,pi/128,         pi/256,pi/512,pi/1024,         pi/2048,pi/4096,pi/8192,pi/16384     };      double tan1[]={1,0.4142135623731,0.19891236737966,         0.098491403357164,0.049126849769467,         0.024548622108925,0.012272462379566,         0.0061360001576234,0.0030679712014227,         0.0015339819910887,0.00076699054434309,         0.00038349521577144,0.00019174760083571};      if(a <= (pi/16384)) {         return a; //因为a的值太小，sin a 约等于 a     }else{          //开始 CORDIC 算法          int negitive = a < 0; // sin(-a) = -sin(a)          double x = 10;          double y = 0;          double theta = 0;          for(i = 0;i < 13;i ++){ //开始迭代              double orix,oriy;              while(theta < a){ //当前角度小于a                  orix = x;                  oriy = y;                  //坐标旋转                  x = orix - tan1[i] * oriy;                  y = tan1[i] * orix + oriy;                  theta += angle[i];              }              if(theta == a){                  if(negitive){                      return -(y/sqrt((x*x+y*y)));                  }else{                      return (y/sqrt((x*x+y*y)));                  }              }else{                  //旋转的弧度超过了a，退回原来增加的角度，同时进入下一次迭代                  theta -= angle[i];                  x = orix;                  y = oriy;              }          }          if(negitive){              return -(y/sqrt((x*x+y*y)));          }else{              return (y/sqrt((x*x+y*y)));          }      }  }  供参考～  代码有问题，函数内定义函数了。你确定是抄别人可以运行的代码～？ 这个好棒！蟹蟹🌹   (我从这儿搜的然后一个个瞎改error🌚)

user: user-0
content: 嗯嗯然后最后的printf我也错了（没加%lf） 谢谢你们~

user: user-2
content: #include "stdio.h" #include "stdlib.h" //#include<windows.h>  int main() { 	double a; 	scanf("%f",&a); 	printf("%f\n",a); 	system("pause"); }  运行结果： 2.141592678971727 -92559604384177266000000000000000000000000000000000000000000000.000000 请按任意键继续. . .  -------------------------------------------------------------------------------------------------   #include "stdio.h" #include "stdlib.h" //#include<windows.h>  int main() { 	double a; 	scanf("%lf",&a); 	printf("%f\n",a); 	system("pause"); }  运行结果 2.141592678971727 2.141593 请按任意键继续. . .

user: user-3
content: int main() {	 double a; int i; scanf("%f",&a);  %lf是是正确的

user: user-3
content: 在上一个帖子里面告诉你了  double要%lf格式在scanf里面输入 否则你输入什么都是0  你可以自己看看，scanf了a后，再输出printf 看看 a是不是0