简单四则运算
思路:
第一个运算数(生成两个随机数,组成真分数或随机生成一个整数),用随机数k标记+,-,*,/,如法炮制,生成另一个运算数。
所用时间:3小时
截图:
代码:
#include<stdio.h> #include<stdlib.h> #include<time.h> void main() { int i,k,a,b,c,d,e,f; srand((unsigned) time(NULL)); for(i=1;i<31;i++) { a = rand() % (100); b= a % 2; if (b == 0) { d = rand() % (100); e = rand() % (100); if (d < e) printf ( "(%d/%d)",d,e); if (d>e) printf ("(%d/%d)",e, d); if (d == e) { if (d == 0) printf ( "(%d/%d)",d ,((rand() % 100) + 2) / 2); else printf( "(%d/%d)",d / 2 ,e); } } else { f = rand() % (100); printf("%d",f) ; } k = rand()%4; if (k == 0) printf ("+"); else if (k == 1)printf ("-"); else if (k == 2) printf ("*"); else printf ("/"); a = rand() % (100); b= a % 2; if (b == 0) { d = rand() % (100); e = rand() % (100); if (d < e) printf ( "(%d/%d)",d,e); if (d>e) printf ("(%d/%d)",e, d); if (d == e) { if (d == 0) printf ( "(%d/%d)",d ,((rand() % 100) + 2) / 2); else printf( "(%d/%d)",d / 2 ,e); } } else { f = rand() % (100); printf("%d",f) ; } printf("=\n") ; } }
代码行数:70行
posted on 2016-03-06 19:09 gaga123456 阅读(221) 评论(2) 编辑 收藏 举报