Editorial
Use the conditional statement to solve the problem. Since , int type is sufficient.
Algorithm realization
Read the input value of .
scanf("%d", &x);
Find the value of .
if (x < 5) y = x * x – 3 * x + 4; else y = x + 7;
Print the result.
printf("%d\n",y);
Java realization
import java.util.*; public class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); int y, x = con.nextInt(); if (x < 5) y = x*x - 3*x + 4; else y = x + 7; System.out.println(y); con.close(); } }
Python realization
Read the input value of .
x = int(input())
Find the value of .
if x < 5: y = x*x - 3*x + 4 else: y = x + 7
Print the result.
print(y)
Go realization
package main import "fmt" func main() { var x, y int fmt.Scanf("%d", &x) if x < 5 { y = x*x - 3*x + 4 } else { y = x + 7 } fmt.Println(y) }
C# realization
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleAppCSharp { class Program { static void Main(string[] args) { int x, y; x = Convert.ToInt32(Console.ReadLine()); if (x >= 5) y = x + 7; else y = x * x - 3 * x + 4; Console.WriteLine("{0}", y); } } }