代码: 全选
#include <stdio.h>
#include <math.h>
main ()
{
int i=1;
float s=0,t;
do
{
t=1.0/(i*i);
s=s+t;
i++;
}while(t>0.0045);
printf ("i=%d\ns=%10f\n",i,s);
getch();
}
还有用pow() 实现x的y次方,gcc同样提示不能识别pow这是为何?
是我的c错了,还是有什么东西没有安装?
代码: 全选
#include <stdio.h>
#include <math.h>
main ()
{
int i=1;
float s=0,t;
do
{
t=1.0/(i*i);
s=s+t;
i++;
}while(t>0.0045);
printf ("i=%d\ns=%10f\n",i,s);
getch();
}
pow()没有问题man getch 写了:代码: 全选
getch(3NCURSES) getch(3NCURSES) NAME getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get (or push back) characters from curses terminal keyboard SYNOPSIS #include <curses.h> int getch(void); int wgetch(WINDOW *win); int mvgetch(int y, int x); int mvwgetch(WINDOW *win, int y, int x); int ungetch(int ch); int has_key(int ch);
也可以在命令行上加上 -lmtusooa 写了:export CFLAGS=-lm
代码: 全选
#include <stdio.h>
#include <sys/ioctl.h>
#include <termios.h>
int getch( );
int main( )
{
char ch;
while(1){
ch = getch( );
printf("You Pressed %c\n", ch);
if(ch == 'E')
break;
}
}
int getch()
{
char ch;
struct termios save, ne;
ioctl(0, TCGETS, &save);
ioctl(0, TCGETS, &ne);
ne.c_lflag &= ~(ECHO | ICANON);
ioctl(0, TCSETS, &ne);
read(0, &ch, 1);
ioctl(0, TCSETS, &save);
return ch;
}
getch()是conio.h里的哇BigSnake.NET 写了:getch 不是标准C函数
代码: 全选
菜鸟学飞中,希望大家多多帮助!