c语言编写程序帮助小学生学习乘法(我是新手)

编写程序帮助小学生学习乘法,使用rand生成两个正的一位整数,然后程序应该显示诸如下面的问题:How much is 6 times 7?学生输入答案,程序针对学生的答案进行检查,如果正确则显示出“very good”,并且提出另一个乘法题,如果错误则显示“no”,然后让学生再次做同一道题知道得出最后正正确的答案。(用函数解决)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
int n,a,b;
a=rand()%9+1;
b=rand()%9+1;
printf("How much is %d times %d?\n",a,b);
printf("输入答案(-1结束): ");
scanf("%d",&n);
while( n!=-1 )
{
if( n==a*b )
{
printf("Very good.\n");
srand(time(NULL));
a=rand()%9+1;
b=rand()%9+1;
printf("How much is %d times %d?\n",a,b);
printf("输入答案(-1结束): ");
scanf("%d",&n);
}
else
{
printf("NO.Please try again.\n");
printf("How much is %d times %d\n?",a,b);
printf("输入答案(-1结束): ");
scanf("%d",&n);
}
}
system("pause");
return 0;
}
这是我自己写 的 可是太多了 我想有个函数使得这个程序简单点 可是我自己想不出来

//这个答案应该可以达到要求
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void fun(int *a,int *b,int *c)
{
srand(time(NULL));
*a=rand()%10;
*b=rand()%10;
*c=(*a)*(*b);

}
void main()
{
int n,a,b,c;
fun(&a,&b,&c);
while(1)
{
printf("How much is %d times %d?\n",a,b);
printf("输入答案(-1结束): ");
scanf("%d",&n);
if(n==-1)break;
if( n==c )
{
printf("Very good.\n");
fun(&a,&b,&c);
}
else
{
printf("NOT .Please try again.\n");
}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-22
#include <stdio.h>
#include <stdlib.h>

int main()
{
int n=0,a=rand()%9+1,b=rand()%9+1;
while( n!=-1 ){
printf("How much is %d times %d?\n",a,b);
printf("输入答案(-1结束): ");
scanf("%d",&n);
if( n==a*b ){
printf("\nVery good!\n");
a=rand()%9+1;
b=rand()%9+1;
}
else
printf("\nNO,Please try again!\n");
}
return 0;
}
这样改,不知道满不满意,我没用函数
第2个回答  2010-05-22
不建议这么直接要程序的,有困难问就行

相关了解……

你可能感兴趣的内容

大家正在搜

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网