if(x0)
創(chuàng)新互聯(lián)專業(yè)成都做網(wǎng)站、網(wǎng)站建設(shè),集網(wǎng)站策劃、網(wǎng)站設(shè)計、網(wǎng)站制作于一體,網(wǎng)站seo、網(wǎng)站優(yōu)化、網(wǎng)站營銷、軟文發(fā)布平臺等專業(yè)人才根據(jù)搜索規(guī)律編程設(shè)計,讓網(wǎng)站在運(yùn)行后,在搜索中有好的表現(xiàn),專業(yè)設(shè)計制作為您帶來效益的網(wǎng)站!讓網(wǎng)站建設(shè)為您創(chuàng)造效益。
y=2*x+1;
else if(x==0) //這里兩個等號在c語言中,才表示相等
y=x;
else
y=1/x;
1. 代碼如下,3)需要實(shí)際運(yùn)行時輸入測試
int main(void)
{
double x, y, f;
printf("Please input 2 double number in the form of x y:\n");
scanf("%lf%lf", x, y);
if(x=0 y0)
f = 2*x*x + 3*x +1/(x+y);
else if(x=0 y=0)
f = 2*x*x + 3*x +1/(1+y*y);
else
f = 3*sin(x+y)/(2*x*x) + 3*x + 1;
printf("x=%lf, y=%lf, f(x, y)=%lf\n", x, y, f);
return 0;
}
2.代碼如下
#include stdio.h
#includemath.h
int main(void)
{
double x, y, f;
printf("Please input 2 double number in the form of x y:\n");
scanf("%lf%lf", x, y);
if(x=0)
{
if(y0)
f = 2*x*x + 3*x +1/(x+y);
else
f = 2*x*x + 3*x +1/(1+y*y);
}
else
f = 3*sin(x+y)/(2*x*x) + 3*x + 1;
printf("x=%lf, y=%lf, f(x, y)=%lf\n", x, y, f);
return 0;
}
3.代碼如下
#include stdio.h
int main(void)
{
int score = 0;
printf("Please input a score between 0-100:\n");
scanf("%d", score);
if(score0 || score100)
printf("Wrong input of score!\n");
else if(score=90 score=100)
printf("A\n");
else if(score=80 score=89)
printf("B\n");
else if(score=70 score=79)
printf("C\n");
else if(score=60 score=69)
printf("D\n");
else
printf("E\n");
return 0;
}
#include
int?main()
{
int?x,y;
scanf("%d",x);
if(0xx10)?y=3*x+2;
else
{if(x=0)?y=0;
else
{if?(x0)?y=x*x;
else?printf("go?die\n");
}
}
printf("%d",y);
return?0;
}該程序的分段函數(shù)如下:
f(x)=3x+2? (0x10)
f(x)=1???????? (x=0)
f(x)?=?x*x??? (x0)
#include stdio.h
#include math.h
void main()
{
float x;
double y;
printf("Please input the value of x:");
scanf("%f",x);
if(x=-10x=4)
{
y=fabs(x-2);
printf("y=%.2f\n",y);
}
else if(x=5x=7)
{
y=x+10;
printf("y=%.2f\n",y);
}
else if(x=8x=12)
{
y=pow(x,4);
printf("y=%.2f\n",y);
}
else
printf("No answer\n");
}
輸入數(shù)用scanf()函數(shù);
分段用switch()函數(shù);
1、絕對值用math庫里面的abs()函數(shù)
2、e^x用math庫里面的pow(e,x)函數(shù)
3、同理指數(shù)的都有pow()函數(shù),
4、cos函數(shù)也是math庫里面的double cos(double x)函數(shù)
自己動手吧,我已經(jīng)把難點(diǎn)全部說出來了!
希望可以幫到你,如果滿意請采納!
scanf是輸入,是不可以指定精度的,所以 scanf("%.1f", x) ;這樣的寫法是錯誤的
而且double是要用lf, 應(yīng)該是scanf("%lf", x) ;
還有double ff();這個聲明要和實(shí)體以及調(diào)用一致,應(yīng)該是double ff( double x) ;
幾個條件不同的可以用if ... else if ... else. 這樣還可以少用一個變量,你那種寫法不推薦
幫你改了下代碼,VC6測試通過,自己看看吧。
#includestdio.h
int main()
{
float x,y;//根據(jù)給定的測試用例,x,y應(yīng)該為float型
scanf("%f",x);//x為float型,所以改為%f
if(x20)
{
y=x+100;
}
else if(x=20x=100)
{
y=x;
}
else
y=x-100;
printf("x=%f,y=%f\n",x,y);
return 0;//缺少分號
}