既可以支持整数四则运算,也可以支持分数四则运算,可定制出题数量的c语言程序

#include<stdio.h>
#include <stdlib.h>
#include<conio.h>
#include<time.h>
#include<string.h>
int main()
{
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    int m=0;
    int i,t,h,n,k,x,y;
    float r;
    scanf("%d",&n);
    srand((unsigned)time(NULL));
    for(i=0;i<n;i++)
    {
        a=rand()%100;
        b=rand()%100;
        c=rand()%100;
        d=rand()%100;
        m=rand()%8;
        if(a<b)
        {
            t=a;
            a=b;
            b=t;
        }
        if(c<d)
        {
            h=c;
            c=d;
            d=h;
        }
    switch(m)
    {
    case 0:
          printf("\n%d+%d=",a,b);break;
    case 1:
        printf("\n%d-%d=",a,b);break;
    case 2:
        printf("\n%d*%d=",a,b);break;
    case 3:
        printf("\n%d/%d=",a,b);break;
    case 4:
        {y=b*c+a*d;x=a*c;}
        printf("\n%d/%d+%d/%d=",a,b,c,d);break;
    case 5:
        {y=b*c-a*d;x=a*c;}
        printf("\n%d/%d-%d/%d=",a,b,c,d);break;
    case 6:
        {y=b*d;x=a*c;}
        printf("\n%d/%d*%d/%d=",a,b,c,d);break;
    case 7:
        {y=b*c;x=a*d;}
        printf("\n%d/%d/%d/%d=",a,b,c,d);break;
    default:
        printf("something is wrong!\n");
        break;
    }
    printf("\n");
    scanf("%d",&k);
  }
    return 0;
}

 

posted @ 2018-10-10 13:21  20163957  阅读(240)  评论(0编辑  收藏  举报