基于visual Studio2013解决C语言竞赛题之0202坐标转换
题目
解决代码及其点评
#include <stdio.h> #include <stdlib.h> #include <math.h> void main() { const double PI=3.14; // 定义pi常量 double r,s; double x,y; printf("please input r and s like (r,s)\n"); scanf_s("%lf,%lf",&r,&s); // 通过scanf_s由用户输入r和s,在vs2013中,scanf函数已经被scanf_s取代 x=r*cos(s*PI/180); // 通过公式计算x和y y=r*sin(s*PI/180); printf("x=%lf,y=%lf\n",x,y); // 通过printf函数输出结果 system("pause"); }这道题目考察相关数学知识和math库的cos和sin函数,以及极坐标概念,极坐标解释大家可以通过百度百科学习
代码下载及其运行
代码下载链接:
http://download.csdn.net/detail/yincheng01/6640481
解压密码为c.itcast.cn
下载解压后用VS2013打开工程文件
点击 “本地Windows调试器” 执行
程序运行结果
等待用户输入r和s,比如输入10,45