我来写一下
#include <stdio.h>
int main()
{
int select;
float x,y;
while(1)
{
puts("*\t坐标的转换\t*");
puts("* 1 - 直角坐标 ->极坐标 *");
puts("* 2 - 极坐标 -> 直角坐标*");
puts("* 0 - 退出\t\t*");
puts("*************************");
printf("请选择:");
scanf("%d",&select);
switch(select)
{
case 0:
return 0;
case 1:
printf("输入直角坐标(x y):");
scanf("%f%f",&x,&y);
printf("\n极坐标为:%f %f\n",sqrt(x*x+y*y),atan(y/x)/3.14*180);
break;
case 2:
printf("输入极坐标(p O):");
scanf("%f%f",&x,&y);
printf("\n直角坐标为:%f %f\n",x*cos(y),y*sin(y));
break;
default:
break;
}
puts("任意键继续……");
getch();
system("cls");
}
getch();
return 0;
}
|