首页 > 其他 > 详细

四则运算

时间:2015-03-27 19:33:35      阅读:173      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int a[100],b[100];
char c[100],sym[4]={+,-,*,/};
void answer(int n);
void main()
{
    int n,o;
    int i;
    char r;
       srand((unsigned)time(NULL));
        while(1)
        {
            printf("输入需要的题目数(0退出):");
            scanf("%d",&n);
            if(n==0) exit(0);
            for(i=0;i<n;i++)
            {
            a[i]=rand()%100;
            b[i]=rand()%100;
            c[i]=sym[rand()%3];
            printf("%d%c%d=\n",a[i],c[i],b[i]);
            }
            printf("是否需要答案?(Y/N)");
            scanf(" %c",&r);
            if(r==Y) answer(n);
        }
}
void answer(int n)
{
    int i,o;
    for(i=0;i<n;i++)
    {
        if(c[i]==sym[0]) o=a[i]+b[i];
        if(c[i]==sym[1]) o=a[i]-b[i];
        if(c[i]==sym[2]) o=a[i]*b[i];
        if(c[i]==sym[3]) o=a[i]/b[i];
        printf("%d%c%d=%d\n",a[i],c[i],b[i],o);
    }
}

 

四则运算

原文:http://www.cnblogs.com/poipoi/p/4372240.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!