#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>
|