.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;
}