求:随机出10道10以内小学加减法的c语言编程 每道题10分最后输出得多少分

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求:随机出10道10以内小学加减法的c语言编程 每道题10分最后输出得多少分相关的知识,希望对你有一定的参考价值。

参考技术A 用rand()产生随机数,rand()会产生从0到一个很大的数,我记不清了,反正很大。如果想出现100以内的,就用rand()%100。你可以定义三个int型整数,两个表示加或者减的对象,另一个标示加或者减,因为只要出现两种情况之一,所以可以用rand()%2,这样只会有0,1两种情况来标示加或者减。下面的就很容易了
int a,b,i,c;
for(i = 0;i < 10;i++)

a = rand()%100;
b = rand()%100;
c = rand()%2;
if(c == 0)//标示加法

printf("%d + %d = %d\n",a,b,a+b);

else

printf("%d - %d = %d\n",a,b,a-b);


大致就这样,希望给你点帮助本回答被提问者和网友采纳
参考技术B 你好@ 是出一道做一道吗

小学生四则运算出题系统——计应193许颖然

一.计划

编写一个小学生四则运算出题程序

二.开发

1.需求分析

作为一名一年级小学生的家长,我希望制作一个出题软件,完成100以内的正整数的加减法题随机产生。以便减轻我的家庭负担。

2.生成设计文档

3.设计复审

4.代码规范

注意大小写,注意缩进,括号一定要配对,注意要分行。

5.具体设计

系统开始,随机产生10道加法或者减法,计算完成后,统计做了多少道题,正确率,以及用了多少时间,系统结束。

6.具体编码

import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;
import java.io.*;

public class Pratices {
public static void main(String[] args) {
  new Pratices().list_Pratices();
  }

  public int random_Num(int range) {
  return (int) (Math.random() * range);
  }
  public void list_Pratices() {
int right = 0;
int wrongtimes = 0;  
int num_1, num_2, temp;
  int type = random_Num(4);
  int score = 0;  
int count = 1;
System.out.println("请输入题目数量:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
  while (count <= n) {
  type = random_Num(2);
  num1 = random_Num(100); //100以内随机数
  num2 = random_Num(100); //100以内的随机数
  wrongtimes = 0;

  if (type == 0)
{
  System.out.print("(" + count + ") " + num1 + " + " + num2+ " = ");//加法
  }
else if(type == 1)
{
  if ((num1 < num2))
{
  temp = num1;
  num1 = num2;
  num2 = temp;
  }
  System.out.print("(" + count + ") " + num1 + " - " + num2+ " = ");//减法
  }
else if(type == 2)

  System.out.print("(" + count + ") " + num1 + " * " + num2+ " = ");//乘法
}
else if(type == 3)
{
if(num2!=0)
  System.out.print("(" + count + ") " + num1 + " / " + num2+ " = ");//除法
else
System.out.println("分母为零");
}

  int answer = this.getAnswer(count);
  boolean flag = check(num1, num2, type, answer, count);
  if (flag) {
  right++;
  System.out.println("回答正确");
  score += this.getScore(wrongtimes);
  } else {
  while (wrongtimes < 2) {
  wrongtimes++;
  System.out.println("回答错误 " + wrongtimes + " 次");
  answer = this.getAnswer(count);
  flag = check(num1, num2, type, answer, count);
  if (flag) {
  score += this.getScore(wrongtimes);
  right++;
  wrongtimes = 0;
  break;
  }
  }
  if (wrongtimes == 3)
  System.out.println("回答错误 ");
  else
  System.out.println("回答正确");
  }
  count++;
  }
  System.out.println("回答正确 : " + right);
  System.out.println("回答错误: " + (10 - right));
  System.out.println("获得分数: " + score);
  System.out.println(getDegree(score));
  }

  public boolean check(int num_1, int num_2, int type, int my_Answer,
  int count) {
  int answer = 0;
  if (type == 1) {
  answer = num_1 - num_2;
  } else if (type == 0) {
  answer = num_1 + num_2;
  }
  return my_Answer == answer;
  }
  public int getAnswer(int count) {
  int my_Answer = 0;
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  try {
  my_Answer = Integer.parseInt(br.readLine());
  } catch (IOException e) {
  e.printStackTrace();
  } catch (NumberFormatException e) {
  System.out.println("输入有误");
  return 0;
  } finally {
  if (count >= n && (br != null)) {//不会超出输入的n
  try {
  br.close();
  } catch (IOException e) {
  e.printStackTrace();
  }
  br = null;
  }
  }
  return my_Answer;
  }
  public int getScore(int wrongtimes) {
  if (wrongtimes == 0) {
  return 10;
  } else if (wrongtimes == 1) {
  return 7;
  } else if (wrongtimes == 2) {
  return 5;
  } else
  return 0;
  }

  public String getDegree(int score) {
  if (score > 90)
  return "SMART";
  else if (score > 80)
  return "GOOD";
  else if (score > 70)
  return "OK";
  else if (score > 60)
  return "PASS";
  else
  return "TRY AGAIN";
  }
  }

以上是关于求:随机出10道10以内小学加减法的c语言编程 每道题10分最后输出得多少分的主要内容,如果未能解决你的问题,请参考以下文章

Java实现随机出题,10道10以内加减法计算

C++编写程序实现小学生数学测验功能

四则运算个人工作流程,计应193,第三组,刘晨龙

小学生四则运算出题系统——计应193许颖然

作一个可供小学生数学运算的程序:10以内的加减乘除,能根据输入的题数计算机自动出题,并判断是不是正确

用C语言写一个 小学生口算出题系统