mdsk.net
当前位置:首页 >> 写程序输入x的值输出y >>

写程序输入x的值输出y

scanf("%d",&x); //y不用输入 if (x<=1) { y=x; printf("%d\n",y);} //条件copyx<=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语言的代码#include int main(int argc, char* argv[]) { double x,y; printf("请输入x:"); scanf("%lf",&x); if(x<1)y=x; else if(x>=10) y=3*x-11; else y=2*x-1; printf("y=%g\n",y); return 0; }

printf("请输入一个整数%d:",x);printf("最大值为:%d\n",x);printf("最小值为:%d",z);我不明白,根据你的题意,应该用多分支的if语句的格式,即:if(表达式1){语句序列1;}else if(表达式2){语句序列2;}else{

#include <stdio.h> int main() { double x, y; printf("input x:"); scanf("%lf", &x); if (x < 1) y = x; else if (x >= 1 && x < 10) y = 2*x-1; else if (x >= 10) y = 3*x-11; printf("y: %lf\n", y); return 0; }

#include "stdio.h" int main() { int x,y; scanf("%d",&x); y=2*x+5; printf("%d",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);}

展开全部#include void main() { int x,y; printf("请输入X的值的大小:"); scanf("%d",&x); if(x { y=x; printf("%d",y); } else if(x>=8) { y=7x-20; printf("%d",y); } else { y=3x-10; printf("%d",y); } }

1234567891011121314151617181920 importjava.util.Scanner; publicclassTest { publicstaticvoidmain(String[] args) { System.out.println("请输入5261x的值:4102"); //提示1653从键盘输入x Scanner scanner=newScanner(System.in);

#include<stdio.h>double f(double x){ if(x>=-5 && x<0 && x!=-1) return 1.0/(x+1); if(x>=0 && x<5) return 1.0/(x+2.0)/(x+2.0); if(x>=5 && x<10) return 1.0/(x+4.0)/(x+4.0)/(x+4.0);}int main(){ double x,y; scanf("%lf",&x); printf("y=%g\n",f(x)); return 0;}

有一函数: x (-5<x<0) y= x-1 (x=0) x+1 (0<x<10) 编写一程序,要求用scanf函数输入x的值,输出y的值. main() { int x; scanf ("%d",&x); if (x>-5&&x<0) printf ("y=%d",x); else if (x=0) printf ("y=%d",x-1); else if (x>0&&x<10) printf ("y=%d",x+1); else printf ("input eeror"); }

fnhp.net | kcjf.net | dkxk.net | 5689.net | zdhh.net | 网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com