首页 > 代码库 > 第十次作业

第十次作业

第一题:

#include<stdio.h>
void sum_diff( float op1, float op2, float *psum, float *pdiff )
{ 
    *psum=op1+op2;
    *pdiff=op1-op2; 
} 
int main() 
{    
    float op1,op2,*psum,*pdiff,sum,diff;
    printf("请输入:op1 op2:");
    scanf("%f%f",&op1,&op2); 
    sum_diff(op1,op2,&sum,&diff); 
    printf("sum=%.2f,diff=%.2f",sum,diff);
    return 0;
} 

  技术分享

 

第二题:

void findmax(int *px,int *py,int *pmax)
{
    if(*px<*py)
        *pmax=*py;
    else
        *pmax=*px;
}
int main()
{
    int x,y,max;
    printf("请输入: x,y:");
    scanf("%d%d",&x,&y);
    findmax(&x,&y,&max);
    printf("max=%d\n",max); 
    return 0;
}

  技术分享

 

第三题:

#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:%.3f\n",fracpart);
    return 0;
}
void splitfloat(float x,int *intpart,float *fracpart)
{
    if(x<0)
    x=-x;
    *intpart=(int)x;
    *fracpart=x-*intpart;
}

  技术分享

第十次作业