哪位大神给点c语言好玩的东西啊?本人是小白
激发下兴趣啊
#include <stdio.h> #include <conio.h> #include <stdlib.h> #include <graphics.h> #include <bios.h> #define ESC 0x11b #define TRUE 1 #define FALSE 0 #define VAR 2 double cal(double *,char *,int *,double); double numtok(char *,int *); int ishave(char,char *); int isnum(char); int deal(char *,double *,char *,int *); double count(double *,char *,int,double); void init_graph(void); void paintxy(void); void init(double *,char *,char *,int *); int main() { double data[200],m,n; char str[200],sign[200]; int poti[50],x,y,key=1; while(TRUE) { printf("Press ESC exit,Other Key Continue\n"); key=bioskey(0); if(key==ESC) break; init(data,str,sign,poti); printf("Input Equation :\n"); printf("y = "); scanf("%s",str+1); str[0]='+'; deal(str,data,sign,poti); init_graph(); paintxy(); for(m=-20.0;m<=20.0;m+=0.001) { n=cal(data,sign,poti,m); if(n>15||n<-15) continue; y=-(int)(n*20)+240; x=(int)(m*20)+320; if(x>=0&&x<=639&&y>=0&&y<=479) putpixel(x,y,RED); } getch(); cleardevice(); } closegraph(); return 0; } void init(double *data,char *str,char *sign,int *poti) { int x; for(x=0;x<199;x++) { if(x<=49) poti[x]=-1; str[x]='\0'; data[x]=0.0; sign[x]='\0'; } } double count(double *data,char *sn,int pos,double ans) { double d1,d2; d1=ans; d2=data[pos]; if(sn[pos]=='*') { if(sn[pos+1]=='*'||sn[pos+1]=='/') return count(data,sn,pos+1,d1*d2); else return d1*d2; } else if(sn[pos]=='/') { if(sn[pos+1]=='*'||sn[pos+1]=='/') return count(data,sn,pos+1,d1/d2); else return d1/d2; } else { printf("Error !\n"); getch(); return 0.0; } } double cal(double *data,char *sign,int *pt,double x) { double ans=0.0,t; int i=0,k=0; while(pt[k]!=-1) { data[pt[k]-1]=x; k++; } while(sign[i]!='\0') { if(ishave(sign[i],"*/")) { i++; continue; } if(!ishave(sign[i+1],"*/")) t=data[i]; else if(ishave(sign[i+1],"*/")) t=count(data,sign,i+1,data[i]); if(sign[i]=='+') ans+=t; else if(sign[i]=='-') ans-=t; i++; } return ans; } int deal(char *expr,double *data,char *sign,int *pt) { char *p; int k=0,l=0,i=0,v=0; p=expr; while(*p) { while(isnum(*p)) p++; if(ishave(*p,"+-*/")) sign[l++]=*p; data[k++]=numtok(p,&v); if(v==TRUE) { pt[i++]=k; v=FALSE; } while(isnum(*p)); p++; } return k; } double numtok(char *sour,int *isvar) { char str_num[17]=""; int k=0,l=0; sour++; if(isnum(*sour)==VAR) { *isvar=TRUE; return 0.0; } while((isnum(*sour)==TRUE)&&l<=15) { str_num[k++]=*sour; sour++; l++; } return atof(str_num); } int ishave(char c,char *s) { int flag=0; while(*s) { if(*s==c) { flag=1; break; } s++; } return flag; } int isnum(char ch) { if((ch>='0'&&ch<='9')||ch=='.'||ch=='e') return TRUE; else if(ch=='x') return VAR; else return FALSE; } void paintxy(void) { int m,n; setcolor(BLUE); line(0,240,639,240); line(320,0,320,479); setcolor(WHITE); outtextxy(325,245,"O"); outtextxy(630,245,"X"); outtextxy(325,5,"Y"); for(m=0;m<=3;m++) { for(n=0;n<=3-m;n++) { putpixel(636+m,240-n,BLUE); putpixel(636+m,240+n,BLUE); putpixel(320+n,3-m,BLUE); putpixel(320-n,3-m,BLUE); } } } void init_graph(void) { int gdriver=DETECT,gmode=2; registerbgidriver(EGAVGA_driver); initgraph(&gdriver,&gmode,"C:\\TC20H"); }只能计算+ - * / ,也不支持省略*