1. 首页 > 科技

C语言 随机生成10个加法算式,输入每个算式的计算结果,判断计算是否正确,输出成绩?

C语言 随机生成10个加法算式,输入每个算式的计算结果,判断计算是否正确,输出成绩?

随机产生10个数,输出结果

金山老师的有点问题~~因为如果重复的的数字出现的话,i应该自减1~~

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

int main( )

{

int a[100]={0},i,k;

srand( (unsigned)time( NULL ) );

for( i = 0; i <10;i++ )

{

k=rand()%90+10;

if(a[k]==0)

{

a[k]=1;

printf( "%d ", k);

}

else i--;

}

return 0;

}

C语言随机数做10以内加法运算,求解

需要 stdlib.h time.h

srand(time(NULL)); //设置种子

int a,b;

a=rand()%10;

b=rand()%10;

printf("%d + %d = %d\n",a,b,a+b);

编程,在屏幕上随机列出10道加法计算题,请用户输入答案,每题10分,最后列出分值。

#include

#include

#include

int add(x,y)

{int s;

s=x+y;

return s;

}

void srand(int x,int y)

{ srand( (unsigned)time( NULL ) ); /*这个就是生成了一个种子*/

x=rand()%100; /*通过rand()%100来生成一个0~99的随机数,并将它赋给k*/

y=rand()%100;

}

main()

{int i,sum=0;

int x,y;

printf("please count these questions\n");

for(i=0;i<10;i++)

{long c;

srand(x,y) ;

add(x,y);

printf("x+y=");

scanf("%ld",&c);

if(c=add(x,y))sum+=10;

}

printf("Your score is %d:\n",sum);

}

C语言题 4.随机生成10道两位数的加法题,由用户给出答案,做对一道加10分,最后输出成绩。

下面是我写的一位数加法运算的程序 ,你可以参考下。祝你好运

#include <iostream>

using namespace std;

void main()

{

cout<<"下面将有十道题:请输入正确答案并按回车"<<endl;

int total=0;

for(int q=1;q<=10;q++)

{

cout<<"这是题目";

cout<<q<<endl;

int a =rand()%10+1;

int b=rand()%10+1;

cout <<a ;

cout<<"+";

cout<<b;

cout<<"="<<endl;

cout<<"请输入答案~"<<endl;

int A;

cin>>A;

if(A==(a+b))

{

cout<<"正确!";

total=total+10;

}

else

cout<<"错误!"<<endl;

}

cout<<"你的得分为:";

cout<<total<<endl;

cout<<"你答错的题目数为:";

cout<<10-total/10<<endl;

}