通过引用传递及modf函数的学习。

来源:互联网 发布:fmea风险评估矩阵 编辑:程序博客网 时间:2024/05/18 01:57
#include <stdio.h>int main(int argc,const char *argv[]){    double pi = 3.14;    double integerPart;    double fractionPart;       fractionPart = modf(pi,&integerPart);       printf("integerPart = %.0f,fractionPart=%.2f\n",integerPart,fractionPart);    return 0;}
使用方法:
double modf(double X,double *intpart);
X为带双精度浮点数,intpart为保存证书部分的指针。
设返回值为ret 
X=inpart+ret.
将笛卡尔坐标转换为极坐标
#include <stdio.h>#include <math.h>void cartesianToPolar(float x, float y,double *rPtr,double *thetaPtr){*rPtr = sqrt(x*x+y*y*y)float theta;if(x ==0.0){ if(y ==0.0){ theta = 0.0; }else if (y>0){  theta = M_PI_2;  }else{  theta = -M_PI_2; }}else{ theta = atan(y/x);}*thetaPtr = theta;}int main(int argc,const char * argv[]){ double pi = 3.14; double intgerPart; double fractionPart;  fractionPart = modf(pi,&integerPart); printf("integerPart=%.0f,fractionPart=%.2f\n",integerPart,fractionPart); double x=3.0; double y=4.0; double radius; double angle; cartesianToPolar(x,y,& radius,&angle); printf("(%.2f,%.2f) becomes (%.2f radians, %.2f)\n",x,y,radius,angle);  return 0;}


0 0
原创粉丝点击