Question
Enter three Integers to determine whether a triangle can be formed
Question objective
The objective is to enable beginners to gradually master the knowledge points and related skills needed to answer this question based on the relationship between triangles. Then, by analyzing the problem-solving ideas step by step, they can finally write their ownCode.
Question Analysis
This topic is intended to allow users to enter three integers (positive integers), and then determine whether the three numbers can form a triangle through computer operations.
Skill Requirements
Variable, data type, operator, input/output, and branch statement
Skill Review
Variable: a variable is a piece of memory space named after it is killed.ProgramThe amount of changes that can occur during running. A variable can be considered as a container. The data stored in the container is determined by the data type that defines the variable.
Data Type: the data type is a set of values and a group of operations defined on the value set.
Operator: The operator is used to execute code operations. operations are performed on more than one operand project.
Input and Output: the console class is used for console input.
Branch statement: If branch statements are divided into single branch, dual branch, and multi-branch statements, which determine whether to execute the operation based on the conditions.
Solutions
Through understanding the basic concepts above, we once again have an understanding of C. How can we solve this problem for beginners?
By convention, we analyze the question first:
The question is to ask the user to input three integers and then determine whether these three numbers can form a triangle. To solve such a problem, we must first find out the key elements in the question.
Through analysis, we can see that the key elements in this question include three integers and one triangle.
The key elements are already available. How can we use these elements?
The first element is three integers, which means that the user enters three integers before performing the next operation.
Where are the three integers entered by the user? The variables are used to define three Integer Variables to store the three integers respectively. For example, int A; int B; int C;
Then the three numbers are received from the user input: A = int. parse (console. readline (); note: the input is a string, and the string cannot be calculated. Therefore, it must be converted to an int type.
The second element is a triangle.
What are the conditions for forming a triangle ??
Triangular three-sided relationship: the sum of the two sides is greater than the third side, and the difference between the two sides is smaller than the third side.
If the condition is met, it is a triangle.
To determine whether the conditions are met, we use the if branch statement to determine whether the conditions are true.
If it is true, it is a triangle, otherwise it is not a triangle.
Code steps
1. Define three variables to store the three input edges.
2. Obtain the three input edges from the interface
3. Calculation Result
4. output the result to the interface.
Code details
Int A, B, C; console. writeline ( " Enter the first edge " ); = Int . Parse (console. Readline (); console. writeline ( " Enter the second edge " ); B = Int . Parse (console. Readline (); console. writeline ( " Enter the third edge " ); C = Int . Parse (console. Readline ()); If (A + B> C & B + C> A & A + C> B ){ If (A = B | A = c | B = C) {console. writeline ( " These three sides can form an isosceles triangle. " );} Else If (A = B & A = C & B = C) {console. writeline ( " These three sides can form an equi-edge triangle. " );} Else {Console. writeline ( " These three sides can form a normal triangle. " );}} Else Console. writeline ( " These three numbers cannot form triangles. " ); Console. readkey ();
Running Effect
Author:Memories of lost youthSource:Http://www.cnblogs.com/lukun/The copyright of this article is shared by the author and the blog. You are welcome to repost this article, but you must keep this statement without the author's consent andArticleThe original text connection is displayed at an obvious location on the page. If you have any problems, you can useHttp://www.cnblogs.com/lukun/ Thank you very much for contacting me.