日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

一个对小学生的随机生成的四则运算试题

發布時間:2024/3/12 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一个对小学生的随机生成的四则运算试题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

List item

一個針對小學生的四則運算試題 ,我這代碼有一個功能就是用文件寫了一個可以查看錯題的功能~就非常簡單

#include<stdio.h> #include<stdlib.h> #include<time.h> #include<string.h> void menu();//菜單函數 void calculate();//隨機產生十道新題目 void read();//上次計算錯題合集 int main() {system("color 8E");printf("\t\t****************************\n");printf("\t\t*這是一套加減乘除隨機的試卷*\n");printf("\t\t* 每題10分,總分為100分 *\n");printf("\t\t*請選擇 1:做十道新題 *\n");printf("\t\t* 2:上次錯題集合 *\n");printf("\t\t****************************\n");menu();return 0; } void menu() {int y;printf("\t\t選擇功能");label: scanf("%d",&y);if(y!=1&&y!=2){printf("\t\t輸入有誤,重新輸入");goto label; }else{switch(y){case 1:calculate();break;case 2:read();break;}}} void calculate() { int rand();srand((unsigned)time(NULL));int i,j,d1,d2,turn,n=0,sorce,elect;float m,num; for(j=0;j<10;j++){FILE *fp;//文件指針變量 if((fp=fopen("1.txt","a+"))==NULL)//建立新文件 {printf("cannot open file\n");exit(0);}i=rand()%4+1;//運算符號 d1=rand()%10+1;d2=rand()%10+1;switch(i){case 1: printf("\t\t\t\t %d+%d= ",d1,d2);//加法 scanf("%f",&num);m=d1+d2;break;case 2:if(d1<d2){turn=d1;d1=d2;d2=turn;}printf("\t\t\t\t%d-%d= ",d1,d2);//減法 scanf("%f",&num);m=d1-d2;break;case 3: printf("\t\t\t\t%d*%d= ",d1,d2);//乘法 scanf("%f",&num);m=d1*d2;break;case 4: printf("\t\t\t\t%d/%d= ",d1,d2);//除法 scanf("%f",&num);m=d1/d2;break;}if(num==m) sorce+=10 ;else{n++;//計算錯題個數 fprintf(fp,"%d,%d\n",d1,d2);}fclose(fp);} printf("\t\t本次答題的最終成績為%d",sorce);printf("\t\t結束請按 0查看錯題請按 2:");label:scanf("%d",&elect); if(elect!=0&&elect!=2){printf("\t\t輸入有誤,重新輸入");goto label; }else{switch(elect){case 0:break;case 2:read();break;}} } void read() {int i;int d1,d2,n;FILE * fp;printf("查看上次錯題集:\n");if((fp=fopen("1.txt","r+"))==NULL){printf("cannot open file\n");exit(0);}while(1){fscanf(fp,"%d,%d",&d1,&d2);if(feof(fp)!=0) break;printf("%d+%d=%d\n",d1,d2,d1+d2);printf("%d-%d=%d\n",d1,d2,d1-d2);printf("%d*%d=%d\n",d1,d2,d1*d2);printf("%d/%d=%d\n",d1,d2,d1/d2);}

}

哈哈 小白剛開始寫~
有bug 歡迎提粗來呀

總結

以上是生活随笔為你收集整理的一个对小学生的随机生成的四则运算试题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。