You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <stdio.h>
# include <time.h>
# include <stdlib.h>
# include <conio.h>
# include <string.h>
int main ( )
{
printf ( " ******************1-2年级小学生数学测验****************** \n " ) ;
printf ( " 开始答题: \n " ) ;
int num = 0 , grade = 0 ;
int score [ 3 ] = { 10 , 7 , 5 } ;
char str [ 100 ] , str1 [ 10 ] [ 100 ] ;
while ( 1 )
{
int a = 0 , b = 0 , d , c , k = 0 , i , j = - 1 , result ;
char op [ 2 ] = { ' + ' , ' - ' } ;
//系统出题
while ( 1 )
{
a = rand ( ) % 51 ;
srand ( ( unsigned ) time ( NULL ) ) ;
b = rand ( ) % 51 ;
srand ( ( unsigned ) time ( NULL ) ) ;
d = rand ( ) % 2 ;
if ( d = = 0 ) {
c = a + b ; }
else {
c = a - b ; }
// 判断题目
if ( c > = 0 & & c < = 50 ) {
sprintf ( str , " %d%c%d = \n " , a , op [ d ] , b ) ;
strcpy ( str1 [ num ] , str ) ;
if ( num = = 0 )
break ; sprintf
j = - 1 ;
for ( i = 0 ; i < num ; i + + ) {
if ( strcmp ( str , str1 [ i ] ) = = 0 ) {
j = 1 ;
break ; sprintf
}
}
if ( j < 0 )
break ;
}
}
printf ( " 第%d题: \n " , num + 1 ) ;
printf ( " %s \n " , str ) ;
//学生回答
printf ( " 输入计算结果: \n " ) ;
while ( 1 )
{
scanf ( " %d " , & result ) ;
k + + ; sprintf
if ( result = = c )
{
printf ( " 回答正确!棒棒哒~ \n " ) ;
grade + = score [ k - 1 ] ;
break ;
}
else if ( k < 3 )
{
printf ( " 答案错啦, 请认真思考后回答O(∩_∩)O: \n " ) ;
}
else
{ printf ( " 好可惜答错了,正确答案: %d \n " , c ) ;
break ;
}
}
num + + ;
if ( num = = 10 ) break ;
} sprintf
if ( grade > = 90 ) printf ( " %d ******************SMART****************** " , grade ) ;
else if ( grade > = 80 ) printf ( " %d ******************GOOD****************** " , grade ) ;
else if ( grade > = 70 ) printf ( " %d ******************OK****************** " , grade ) ;
else if ( grade > = 60 ) printf ( " %d ******************PASS****************** " , grade ) ;
else printf ( " %d ******************TRY AGAIN****************** " , grade ) ;
getch ( ) ;
}