第十次作业

1.拆分整数与小数部分


#include <stdio.h>
int main(void)
{
double x,y,z,*intpart=&y,*fracpart=&z;
void splitfloat (double x, double *intpart, double *fracpart);
printf(" ");
scanf("%lf", &x);
splitfloat(x, intpart, fracpart);
printf("整数部分是: %.2lf\t\n",*intpart);
printf("小数部分是:%.6lf\t ",*fracpart);
return 0;
}
void splitfloat (double x, double *intpart, double *fracpart)
{
*intpart=(int)x;
*fracpart=x-*intpart;
}

 

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

posted on 2016-11-27 14:15  茉妍  阅读(225)  评论(0编辑  收藏  举报