1.拆分整数与小数部分
#include <stdio.h> void sum_diff(float op1,float op2,float *psum , float* pdiff) { *psum = op1+op2; *pdiff = op1-op2; } int main(void) { float f1=11.1, f2=1.5, sum, diff; sum_diff(f1, f2, &sum, &diff); printf("sum=%g, diff=%g\n", sum, diff); }
2.最大值
#include<stdio.h> void findmax( int *px, int *py, int *pmax ) { *pmax = *px; if(*py > *pmax) *pmax = *py; } int main(void) { int max,x,y; scanf("%d%d",&x,&y); findmax(&x,&y,&max); printf("max:%d\n",max); }
3.计算差和
#include <stdio.h> void sum_diff(float op1,float op2,float *psum , float* pdiff) { *psum = op1+op2; *pdiff = op1-op2; } int main(void) { float f1=11.1, f2=1.5, sum, diff; sum_diff(f1, f2, &sum, &diff); printf("sum=%g, diff=%g\n", sum, diff); }