ZKX's LAB

从键盘输入x的值 求y的值并输出 编写程序,从键盘输入x的值,计算并输出分段函数y的值y=-1(x<0)

2021-04-28知识7

编写程序,完成下面分段函数y的计算,从键盘输入x值,并输出y的值。 #includedouble fun(double x){double y;if(x)y=2*x+10;else y=3*x+20;return y;}int main(){double x;printf(\"Enter the value of x:\");scanf(\"%f\",x);printf(\"The value of y is%f.\\n\",fun(x));return 0;}

编写一个程序,从键盘输入x的值,输出y的值。要详细过程,谢谢了 import java.util.Scanner;public class Test {public static void main(String[]args){System.out.println(\"请输入x的值:\");提示从键盘输入xScanner scanner=new Scanner(System.in);String strx=scanner.next();获取从键盘输入的字符串int x=Integer.parseInt(strx);把字符串x 转为整型xint y=0;if(x){y=x;}else if(x){y=3*x-2;}else if(x){y=4*x+1;}else{y=5*x;}System.out.println(\"y的值为:\"+y);}}

编写程序,要求从键盘输入x的值,输出y的值。 #includedouble f(double x){if(x>;=-5&x。1)return 1.0/(x+1);if(x>;=0&x)return 1.0/(x+2.0)/(x+2.0);if(x>;=5&x)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;}

随机阅读

qrcode
访问手机版