计算两数的和与差
#include<stdio.h> void sum_diff(float op1,float op2,float *psum,float *pdiff); int main(void) { float op1,op2,sum,diff; printf("input op1 and op2:"); scanf("%f%f",&op1,&op2); sum_diff(op1,op2,&sum,&diff); printf("%f+%f=%f,%f-%f=%f\n",op1,op2,sum,op1,op2,diff); return 0; } void sum_diff(float op1,float op2,float *psum,float *pdiff) { *psum=op1+op2; *pdiff=op1-op2; }
利用指针找最大值
#include<stdio.h> void findmax(int *px,int *py,int *pmax); int main() { int x,y,max; printf("input x and y:"); scanf("%d%d",&x,&y); findmax(&x,&y,&max); printf("%d\n",max); return 0; } void findmax(int *px,int *py,int *pmax) { if(*px<*py) *pmax=*py; else *pmax=*px; }
拆分实数的整数与小数部分
#include<stdio.h> void splitfloat(float x,int *intpart,float *fracpart); int main() { float x,fracpart; int intpart; printf("input x:"); scanf("%f",&x); splitfloat(x,&intpart,&fracpart); printf("the intpart is:%d\n",intpart); printf("the fracaprt is:%f\n",fracpart); return 0; } void splitfloat(float x,int *intpart,float *fracpart) { if(x<0) x=-x; *intpart=(int)x; *fracpart=x-*intpart; }
一、知识点
1.
时间: 2024-10-03 09:09:08