首页 > 代码库 > 附加题

附加题

41页习题:

1.

#include<stdio.h>
int main() 
{    
    double x,average,sum=0; 
    int i;
    for(i=0;i<4;i++)
    {
    scanf("%lf",&x);
    sum=sum+x; 
    }
    average=(sum/4);
    printf("sum=%.1lf,average=%.1lf",sum,average); 

    return 0;
}

2.

#include<stdio.h>
#include<math.h>
int main()
{
double x,y;
printf("Enter x(x>=0):\n");
scanf("%lf",&x);
if(x<=50){
y=0.53*x;    
}
else if(x>50)
{
y=(0.53+0.05)*x;
}
printf("y=f(%f)=%.2f\n",x,y);
return 0;
}

3.

#include<stdio.h>
int main()
{
int m,n;
double i,sum=0,p;
printf("输入 m,n:");
scanf("%d%d",&m,&n);
for(i=m;i<=n;i++)
{
p=i*i+1/i;
sum=sum+p; 
}
printf("sum=%.6lf",sum);
return 0;
}

4.

#include<stdio.h>
int main()
{    
    int i,n;
    double item,sum,den,ben,flag;
    printf("Enter n:");
    scanf("%d",&n);
    flag=1;
    den=1;
    sum=0;
    ben=1;
    for(i=1;i<=n;i++)
    {    item=flag*(ben/den);
        flag=-flag;
        sum=sum+item;
        den=den+2; 
        ben=ben+1;
    }
    printf("sum=%lf\n",sum);

    return 0;
} 

 

附加题