两个数的四则运算。

来源:互联网 发布:小米快传软件 编辑:程序博客网 时间:2024/05/16 23:46
//二元四则运算int Arithmoter(int argu1, int argu2, int doit, unsigned int *P1,unsigned int *P2){unsigned int res=0;unsigned int yu=0;switch(doit){case 0:    res=argu1+argu2;break;case 1:res=argu1-argu2;break;case 2:res=argu1*argu2;break;case 3:res=argu1/argu2;yu=res%argu2;break;}*P1=res;*P2=yu;         return 0;/*//testprintf("res=%d ",res);printf("yu=%d ",yu);printf("*P_res1=%d ",*P_res1);printf("*P_res2=%d ",*P_res2);printf("%d...%d",*P1,*P2);*/}void main(){unsigned int argu1,argu2,doit;unsigned int res1=0;unsigned int res2=0;unsigned int *P_res1=&res1;unsigned int *P_res2=&res2;//char temp;char Sdo[4];    Sdo[0]='+';Sdo[1]='-';Sdo[2]='*';Sdo[3]='/';srand(time(NULL));    argu1=rand()%100;argu2=rand()%100;srand(time(NULL)+rand());doit=rand()%4;        /*Here is a test, by input arguments from keyboard.        printf("argu1:\n");    scanf("%d",&argu1);    printf("argu2:\n");    scanf("%d",&argu2);    printf("doit:\n");    scanf("%d",&doit);    */Arithmoter(argu1, argu2, doit, &res1, &res2);/*I want to reach the same output by this line with the next 3,but it finally give wrong  results.      //.....................................................  //printf("%d %c %d = %d\n",argu1,argu2,Sdo[doit],res);  //.....................................................*/    printf("%d ",argu1);    printf("%c ",Sdo[doit]);if (0!=*P_res2){    printf("%d = %d...%d\n",argu2,res1,res2);}else{    printf("%d = %d\n",argu2,*P_res1);}system("Pause");    //scanf("%d",&temp);}

 
原创粉丝点击