当前位置:首页 » 编程语言 » c语言代码编程实现函数y的值
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言代码编程实现函数y的值

发布时间: 2022-06-16 23:35:08

‘壹’ 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");