码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算

时间:2018-10-07 11:28:47      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:方法   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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!