小學數學程式設計題

Jongper發表於2020-10-24

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
char m,n;
int a,b,c,d,e,f,g,t=0,i;
int begin,end;
begin = time(NULL);
end = time(NULL);
printf(“請輸入使用者ID:”);
scanf("%c%c%d",&m,&n,&a);
if((m>=‘A’&&m<=‘Z’)&&(n>=‘A’&&n<=‘Z’)&&(a>=1000&&a<=9999)){
printf(“請選擇以下三種選擇:\n”) ;
printf("(1)開始測試\n");
printf("(2)檢查分數\n");
printf("(3)退出\n");
}
else printf(“使用者名稱格式錯誤!無法登入!”);
scanf("%d",&g);
if(1<=g&&g<=3){
switch(g){
case 1:
for(i=0;i<10;i++){
a = rand()%100+1;
b = rand()%100+1;
e = rand()%4+1;
switch(e){
case 1:d=a+b;printf("%d+%d=",a,b);scanf("%d",&f);break;
case 2:d=a-b;printf("%d-%d=",a,b);scanf("%d",&f);break;
case 3:d=ab;printf("%d%d=",a,b);scanf("%d",&f);break;
case 4:d=a/b;printf("%d/%d=",a,b);scanf("%d",&f);break;
}
if(d==f){
printf(“回答正確!\n”);
t=t+1;
}else{
printf(“回答錯誤!答案是:%d\n”,d);
}
printf(“總分=%d\n”,t*10);
end = time(NULL);
printf(“time = %d\n”,end-begin);
system(“pause”);
}break;
case 2:
break;
case 3:
printf(“成功退出!”);
break;
}
}
}

#include
#include
using namespace std;
int main()
{
FILE *fp;
fp=fopen(“2.txt”,“w”);
int n;
cin>>n;
cout<<n<<endl;
fprintf(fp,"%d",n);
fclose(fp);
return 0;
}

相關文章