C语言多结构文件完成两个数的加减乘除

.h文件用来声明函数,

#ifndef Int_Cal_H
#define	Int_Cal_H	//防止头文件重复利用

int Add(int a,int b);//加法函数声明

int Mult(int a,int b);//乘法函数声明

int Sub(int a,int b);//减法函数声明

int Div(int a,int b);//除法函数声明

#endif

用来函数定义的源文件 

#include<stdio.h>
#include"Int_cal.h"


int Add(int a,int b)
{
	return a+b;
}

int Mult(int a,int b)
{
	return a*b;
}
int Sub(int a,int b)
{
	return a-b;
}
int Div(int a,int b)
{
	if(b!=0)
	{
		return a/b;
	}
	printf("error data\n");
}

main函数 

#include<stdio.h>
#include"Int_Cal.h"

int main()
{
	char start='\0';
	char ch='\0';
	int result=0;
	int a=0,b=0;
	
	do
	{
		printf("Input data and +-*/:  ");
		scanf("%d %c %d",&a,&ch,&b);
		switch (ch)
		{
			case '+' :result=Add(a,b);   break;
			case '-' :result=Sub(a,b);   break;
			case '*' :result=Mult(a,b);  break;
			case '/' :result=Div(a,b);   break;	
		}
		printf("%d%c%d=%d\n",a,ch,b,result);
		printf("是否继续(Y/y):  ");
		fflush(stdin);
		scanf("%c",&start);
	} while (start=='Y'||start=='y');
			
	return 0;
}

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值