1.编写程序,将直角坐标值转化为极坐标。极坐标的公式是:
c= sqrt(x*x+y*y), q=arctan(y/x)
函数f的定义为:void fun(double x,double y,double *c,double *q),其中x, y为输入的直角坐标,指针c, q用于返回计算得到的极坐标值。
主程序读入x, y,输出c, q,其中c,q保留小数点后面两位。
#include "Conio.h"#include "graphics.h"
#define closegr closegraph
void initgr(void) /* BGI初始化 */
{
int gd = DETECT, gm = 0/* 和gd = VGA,gm = VGAHI是同样效果 */
registerbgidriver(EGAVGA_driver)/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */
initgraph(&gd, &gm, "")
}
void DrawCoord()
void Drawstg()
void Drawcurve()
int main(void)
{
initgr()/* BGI初始化 */
DrawCoord()
Drawstg()
Drawcurve()
getch()/* 暂停一下,看看前面绘图代码的运行结果 */
closegr()/* 恢复TEXT屏幕模式 */
return 0
}
void DrawCoord() /*画坐标系*/
{
line(50,40,50,400)/*y轴*/
line(50,400,600,400)/*x轴*/
line(50,40,45,50)/*箭头*/
line(50,40,55,50)
line(600,400,590,395)
line(600,400,590,405)
outtextxy(35,45,"y")
outtextxy(590,410,"x")
outtextxy(40,410,"O")
}
void Drawstg() /*画标尺*/
{
int x,y,i
x=50,y=400
for(i=0i<17i++)
{
line(x+5,y,x,y)
y-=20
}
x=50,y=400
for(i=0i<26i++)
{
line(x,y-5,x,y)
x+=20
}
}
void Drawcurve()/*画图示例*/
{
line(50,400,500,400-250)
}
acos()
的形参当然有范围,-1,至1,闭区间,基本的数学知识,如果朝界控制台会显示-1.#IND,表示数据超界;关于坐标的函数当然有,需要用到结构体COORD,以及头文件windows.h
具体代码如下:
#include
<windows.h>
#include
<stdio.h>
void
gotoxy(int
x,int
y)
{
COORD
coord
coord.X=x
coord.Y=y
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord)
}
void
main()
{
gotoxy(50,60)
printf("I
LOVE
YOU")
}
这个程序就实现了移动光标到指定位置,然后输出指定的内容。