两个数的四则运算。

//二元四则运算
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;
	/*
	//test
	printf("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);


}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值