标签:方法 int 设计思想 运算符 for循环 time 重复 源程序 i++
设计思想:
从c++方法出发,按照所给出的要求,先用代码将运算符输入程序中,用printf、scanf语句保证可以定制出题数目,用for循环实现出题数目并保证不重复,用rand语句保证一到一百以内的数的四则运算。
源程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int n, m, i, j, num;
srand(time(0));
char sc[] = {‘+‘, ‘-‘, ‘*‘, ‘/‘};
printf("输入生成的算式个数:");
scanf("%d", &n);
for(i=0; i<n; i++){
m = 1;
for(j=0; j<m; j++){
num = rand() % 100 + 1;
printf("%d %c ", num, sc[rand()%4]);
}
printf("%d", rand() % 100 + 1);
printf(" =\n");
}
return 0;
}
标签:方法 int 设计思想 运算符 for循环 time 重复 源程序 i++
原文地址:https://www.cnblogs.com/zhs20160715/p/9749587.html