四则运算

设计思想:

        从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;

 

posted on 2018-10-07 11:06  争当博主  阅读(94)  评论(0编辑  收藏  举报

导航