#include math.h
成都創(chuàng)新互聯(lián)是專(zhuān)業(yè)的寶應(yīng)網(wǎng)站建設(shè)公司,寶應(yīng)接單;提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行寶應(yīng)網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
int main()
{
double x,y;
scanf("%lf",x);
if (x0)
y=0.5*(-x);
else
if (x10)
y=exp(x)+3;
else
if(x20)
y=log10(x);
else
if (x30)
y=pow(x,1.5);
else
if (x50)
y=pow (x,0.5)-1;
else
y=3*cos(x);
printf("y=%lf\n",y);
return 0;
}
擴(kuò)展資料
return 0代表程序正常退出。return是C++預(yù)定義的語(yǔ)句,它提供了終止函數(shù)執(zhí)行的一種方式。當(dāng)return語(yǔ)句提供了一個(gè)值時(shí),這個(gè)值就成為函數(shù)的返回值。
return語(yǔ)句用來(lái)結(jié)束循環(huán),或返回一個(gè)函數(shù)的值。
1、return 0,說(shuō)明程序正常退出,返回到主程序繼續(xù)往下執(zhí)行。
2、return 1,說(shuō)明程序異常退出,返回主調(diào)函數(shù)來(lái)處理,繼續(xù)往下執(zhí)行。return 0或return 1對(duì)程序執(zhí)行的順序沒(méi)有影響,只是大家習(xí)慣于使用return(0)退出子程序而已。
1. 代碼如下,3)需要實(shí)際運(yùn)行時(shí)輸入測(cè)試
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");
}