- #include <stdio.h>
- /**
- * 实现利用指针进行加减乘除
- *
- * @param x 输入值
- * @param y 输入值
- * @param add 加法指针
- * @param jian 减法指针
- * @param cheng 乘法指针
- * @param chu 除法指针
- */
- void calculate(int x,int y,int *add,int *jian,int *cheng,float *chu){
- *add =x+y;
- *jian = x-y;
- *cheng =x*y;
- *chu = x/(float)y;
- }
- int main(int argc, const char * argv[]) {
- int add=0;
- int jian=0;
- int cheng=0;
- float chu =0.0f;
- calculate(10,5, &add, &jian, &cheng, &chu);
- printf("10+5=%d\n",add);
- printf("10-5=%d\n",jian);
- printf("10*5=%d\n",cheng);
- printf("10/5=%.2f\n",chu);
-
-
- return 0;
- }
复制代码
|
|