您的位置:首页 > 移动开发 > 微信开发

头脑有些不灵活了,写个加减法的小程序动动脑,哈哈。

2016-04-07 22:44 399 查看
C语言写的,获取两个100以内的随机数,测试加减的正确。



源码如下:

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#define NUMBER_OF_TIME 10

void MaxMinChange(int * a, int *b);

int main()

{

 int value1,value2,value3,total,inputvalue,i;

 srand((unsigned)time(NULL));

 printf("math test begain:\n");

 for(i=0;i<NUMBER_OF_TIME;i++)

 {

  value1 = rand() % 101;

  value2 = rand() % 101;

  value3 = rand() % 2;

  if(value3)

  {

   total = value1 + value2;

   printf("%d + %d = ",value1,value2);

  }

  else

  {

   MaxMinChange(&value1,&value2);

   total = value1 - value2;

   printf("%d - %d = ",value1,value2);

  }

  scanf("%d",&inputvalue);

  if(total == inputvalue)

  {

   printf("You are right !!\n");

  }

  else

  {

   printf("You are wrong !!\n");

  }

 }

}

void MaxMinChange(int *a,int *b)

{

 int Max,Min,c;

 Max = *a;

 Min = *b;

 if(Max < Min)

 {

  c = Max;

  Max = Min;

  Min = c;

 }

 *a = Max;

 *b = Min;

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: