第十周—小学生初步计算

来源:互联网 发布:我知女人心阅读全文 编辑:程序博客网 时间:2024/05/01 12:40

问题与代码:

作者:邓哲

时间:2016年11月7日12:41:51

#include <stdio.h>#include <stdlib.h>#include <time.h>int main(){    int a,b,d,t=0,i,sum=0;    srand(time(0));    for(i=1; i<10; i++)    {        a=rand()%10+1;        b=rand()%10+1;        printf("%d+%d=",a,b);        scanf("%d",&d);        sum=a+b;        if(d==sum)        {            printf("正确!\n");            t=t+1;        }        else            printf("错误!\n");    }    printf("分数为%d",t*10);    return 0;}


知识点总结:srand(time(0))随机顶序 ,后便每次运用随机数的时候都需要rand。



1 0
原创粉丝点击