『壹』 c語言編程: 編程實現根據以下函數關系,對輸入的每個x值,並計算出y的值
#include <stdio.h>
#include <math.h>
int main()
{
double x,y;
scanf("%lf",&x);
y=x<5?x+2:sqrt(x);
printf("%lf ",y);
return 0;
}
『貳』 用C語言寫出實現以下函數的對應程序,要求:輸入X,計算並輸出函數Y的值,保留兩位小數。
#include<stdio.h>
float x,y;
void main()
{
printf("Please Input x:\n");
scanf("%f",&x);
if(x==0) y=20;
else if(x<0)
y=x+10;
else y=30*x;
printf("Y=%5.2f",y);
}
『叄』 根據以下函數關系,c語言編程實現從鍵盤上輸入x的值,計算出y的值
#include "stdio.h"
int main(void)
{
專int x;
scanf("%d", &x);
if (x > 0)
屬printf("1");
else if (x == 0)
printf("0");
else
printf("-1");
return 0;
}
『肆』 c語言編程,編寫一個函數,根據形參x和y的關系,返回不同的值
代碼如下:
#include<stdio.h>
#include<stdlib.h>
intfunc(intx,inty)
{
if(x>y){
return1;
}
elseif(x<y){
return-1;
}
else{
return0;
}
}
intmain()
{
intx,y,ret;
printf("請輸入x,y的值:");
scanf("%d%d",&x,&y);
ret=func(x,y);
printf("%d ",ret);
system("pause");
return0;
}
運行結果:
『伍』 c語言,編寫程序用scanf函數輸入x的值,計算並輸出y的值。
scanf("%d",&x);
//y不用輸入
if
(x<=1)
{
y=x;
printf("%d\n",y);}
//條件x<=1成立時,這兩句都要執行,所以要用{}變成復合語句。
else
if(x>1&&x<10)
{
y=2*x+1;
printf("%d\n",y);}
//同上
else
{y=3*x+1;
printf("%d\n",y);}
//同上
更好的是:
scanf("%d",&x);
if
(x<=1)
y=x;
else
if(x>1&&x<10)
y=2*x+1;
else
y=3*x+1;
);
//
y求值
printf("%d\n",y);
//輸出y
『陸』 C語言題目 編程 根據以下函數,編程序計算y的值。
#include <stdio.h>
#include <cmath>
int main()
{
int x;
printf("請輸入x的值:");
scanf("%d", &x);
if ( x <= -20 )
{
int y = 5*x+20;
printf(" x = %d , y = %d", x, y );
}
else if ( x <= 20 )
{
float y = 1.0/(2+sin(1.0*x) );
printf(" x = %d , y = %f", x, y );
}
else
{
int y = x*x*x*x*x*x-1;
printf(" x = %d , y = %d", x, y );
}
return 0;
}
『柒』 C語言編程函數輸入X求Y
#include<stdio.h>
intmain()
{
intx,y;
printf("請輸入x:");
scanf("%d",&x);//由用戶輸入x
if(x<0)//從小到大,如果x不小於0
y=x+2;
elseif(x<20)//如果執行這里,x就一定大於0,因為如果x小於0,在上一個if就被執行了
y=3*x+1;
else//到這里,x就一定不小於20,那就是x>=20所以就直接執行.
y=4*x*x-9;
printf("y=%d",y);
return0;
}
『捌』 1、c語言 編程實現下列函數的計算,輸入x的值,輸出y的值
可以用if語句來實現:
#include<stdio.h>
main()
{
double
x,y;
scanf("%lf",&x);
if(x<0)y=3*x+2;
else
y=-x+1;
printf("%lf\n",y);
}
『玖』 C語言編程: 編寫一個程序,根據下列公式,實現根據輸入的x值,求出y的值,並輸出x和y的值
這題就是定義一個獨立函數,參數為n和x,根據n的值,判斷並選擇多項式中的一個式子來計算y的值。計算結果和x的值可直接在函數中列印,也可放數組做返回值返回,在主函數中接收並列印輸出。
下面代碼是帶返回值的寫法:
#include <stdio.h>
int* funP(int n,int x);
int main()
{
int *rn=NULL,n,x;
while(1)
{
printf("請輸入n和x的值:");
scanf("%d%d",&n,&x);
rn=funP(n,x);
if(rn)
printf("x的值為%d,y的值為%d ",rn[0],rn[1]);
}
return 0;
}
int* funP(int n,int x)
{
static int rn[2];//數組0保存x,1保存結果y
rn[0]=x;
if(n==1 || n==2 || n==3 || n==4 || n==8)
rn[1]=x+1;
else if(n==5)
rn[1]=x+100;
else if(n==6 || n<=0)
rn[1]=x*x+2;
else if(n==7)
rn[1]=x*x*x+3;
else
rn[1]=0;
return rn;
}
『拾』 C語言寫有一個函數 輸入X,輸出Y值如題 謝謝了
我把核心的給你寫一下,編程還是要自己動手,要不你永遠也學不會的。
scanf("%f",&x);
if(x>=-2&&x<0)
y=x;
else
if(x==0)
y=x-1;
else
if(x>0&&x<=2)
y=x+1;
else
printf("輸入有誤\n");