void main()
{
int x,y
scanf("%d",x)
if(0<x&&x<=2)
y=x+1
if(x==0)
y=x-1
if(-2<=x&&x<0)
y=x
printf("y=%d",y)
}
如果想输小数的话把int 改成float,把 %d改成%f,就行了
#include <stdio.h>int main()
{
int x , y
scanf("%d",&x)
if(x < 1)
{
y = x - 1
printf("%d %d\n", x, y)
}else if(x > 1 || x == 1){
y = 2 * x + 1
printf("%d %d\n", x, y)
}
}
C语言编程: 输入x的值,按下面公式计算并输出y的值(保留两位小数) 123456789101112#include<stdio.h>#include<math.h>int main(){double x, y scanf ( %lf , &x) if (x >0)y = sqrt(2*x) else if (x <0)y = 1.0/(3*exp(x)) else y = 0 printf ( %.2f\n , y) return 0}欢迎分享,转载请注明来源:内存溢出
评论列表(0条)