当前位置:网站首页>Write a program, input x with scanf function, output y value.

Write a program, input x with scanf function, output y value.

2020-12-19 12:01:32 osc_ o44vh5qb

There is a function :
y=x²+2x-6  (x<0,x≠-3)
y=x²-5x+6  (0≤x<10,x≠2,x≠3)
y=x²-x-15  (x=-3,x=2,x=3,x≧10)


Their thinking : First use scanf Function input , Reuse if Statement to calculate the equation .
take x Use... According to the title if Statements are divided into three ranges , And the corresponding range of y Function of .

notes :1.if In the sentence “!=" It means not equal to .
2.if In the sentence “&&” yes And It means
for example if(x<0&&x!=-3) Meaning for : If x<0 And x!=3, Then run the corresponding code .

1.#include<stdio.h>
int main()
{
   
   
	int x,y;
	printf("x=");                // Input x Value 
	scanf("%d",&x);
	if(x<0&&x!=-3)               //x<0,x≠-3
	{
   
   
		y=x*x-5*x+6;             // Output when the above conditions are met y The value of is 
	}
	else
		if(0<=x<10&&x!=2&&x!=3)  //0≤x<10,x≠2,x≠3
			{
   
   
				y=x*x-5*x+6;     // Output when the above conditions are met y The value of is 
		}
		else
			{
   
   
				y=x*x-x-15;      // Otherwise output y The value of is 
		}
		printf("y The value of is :%d",y);
	return 0;
}

Running result display :
Input x=-1 obtain y The value of is 12
 Insert picture description here
Input x=3 obtain y The value of is -9
 Insert picture description here
Input x=1 obtain y The value of is 2
 Insert picture description here
If there is something you don't understand or correct , Welcome to mention it in the comments , I will try my best to answer (^^)
You are welcome to make correction comments , Common progress !!!







版权声明
本文为[osc_ o44vh5qb]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201219120042478W.html