#include iostream
創(chuàng)新互聯(lián)公司主營(yíng)潯陽(yáng)網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶App定制開(kāi)發(fā),潯陽(yáng)h5小程序制作搭建,潯陽(yáng)網(wǎng)站營(yíng)銷(xiāo)推廣歡迎潯陽(yáng)等地區(qū)企業(yè)咨詢(xún)
#include cmath
int main()
{
using namespace std;
cout"請(qǐng)輸入x的值(x10):";
double x,y;
cinx;
int n;
if(x=10x20)
n=1;
else if(x=20x30)
n=2;
else if(x=30x40)
n=3;
else if(x=40x50)
n=4;
else if(x=50)
n=5;
switch(n)
{
case 1:
y=log10(x);
break;
case 2:
y=log10(x)/log10(3);
break;
case 3:
y=cos(x);
break;
case 4:
y=pow(x,5);
break;
case 5:
y=1.0/tan(x);
break;
default:
cout"\n你輸入的值不在取值范圍內(nèi),再見(jiàn)!\n";
break;
}
if(x10)
cout"\n本函數(shù)的y值為:"y"。*^o^*\n";
return 0;
}
#includestdio.h
int?main()
{
int?x,y;
scanf("%d",x);
if(x-10)
y=0;
else?if(x100)?y=5*x+1;
else
??y?=?5*x?+?1;?//這個(gè)表達(dá)式的值是什么啊
printf("%d\n",y);
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");
}
#include math.h
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)退出子程序而已。
#includestdio.h
void?main()
{?
float?x,y;
scanf("%f",x);
if(x0)
y=x*x;
else?if(x==0)
y=2*x-1;
else?
y=-3*x*x-1?;//這里少個(gè)分號(hào)
printf("%.2f",y);
}
#include stdio.h
#include math.h
int main(void)
{
int repeat, ri;
double x, y;
scanf("%d", repeat);
for(ri = 1; ri = repeat; ri++){
scanf("%lf",x);
y=x=0?sqrt(x):pow(x+1,2)+2*x+1/x;
printf("f(%.2f) = %.2f\n", x, y);
}
}