|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
输入一个整数n,表示后面总共要输入n组测试数据;
然后输入n组测试数据,每组测试数据是一个双精度浮点数x。
输出
根据输入的n组测试数据,对应输出n个输出结果,每个输出结果单独占一行,即每个输出结果后要加换行符
#include <stdio.h>
#include <math.h>
int main()
{
double x,y;
int i;
while(scanf("%lf",&x)!=EOF)
{
if(x<0)
{
x=abs(x);
y=x/2;
}
else if(x>=0&&x<=10)
{
y=3+exp(x);
}
else if(x>=10&&x<20)
{
y=log10(x);
}
else if(x>=20&&x<30)
{
y=pow(x,1.5);
}
else if(x>=30&&x<50)
{
y=pow(x,0.5)-1;
}
else
{
y=3*cos(x);
}
printf("y=%lf",y);
}
return 0;
}
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int i , n ;
- printf("enter data number : ") ;
- scanf("%d" , & n) ;
- if(n > 0) {
- double x[n] , y[n] ;
- for(i = 0 ; i < n ; i ++) {
- printf("enter x(%d) : " , i + 1) ;
- scanf("%lf" , & x[i]) ;
- }
- for(i = 0 ; i < n ; i ++) {
- if(x[i] < 0) y[i] = abs(x[i]) / 2 ;
- else if(x[i] >= 0 && x[i] < 10) y[i] = 3 + exp(x[i]) ;
- else if(x[i] >= 10 && x[i] < 20) y[i] = log10(x[i]) ;
- else if(x[i] >= 20 && x[i] < 30) y[i] = pow(x[i] , 1.5) ;
- else if(x[i] >= 30 && x[i] < 50) y[i] = pow(x[i] , 0.5) - 1 ;
- else y[i] = 3 * cos(x[i]) ;
- }
- for(i = 0 ; i < n ; i ++) printf("%3d : x = %lf , y = %lf\n" , i + 1 , x[i] , y[i]) ;
- }
- }
复制代码
编译、运行实况:
- D:\00.Excise\C>g++ -o x x.c
- D:\00.Excise\C>x
- enter data number : 6
- enter x(1) : -5
- enter x(2) : 5
- enter x(3) : 15
- enter x(4) : 25
- enter x(5) : 35
- enter x(6) : 45
- 1 : x = -5.000000 , y = 2.500000
- 2 : x = 5.000000 , y = 151.413159
- 3 : x = 15.000000 , y = 1.176091
- 4 : x = 25.000000 , y = 125.000000
- 5 : x = 35.000000 , y = 4.916080
- 6 : x = 45.000000 , y = 5.708204
- D:\00.Excise\C>
复制代码
|
|