Original article, copyright belongs to Hu Tian Fa (hutianfa@163.com) All, reprint please indicate the source:
Http://blog.csdn.net/aidisheng/archive/2008/09/02/2868712.aspx
In the course of teaching, it was not a good habit that many students thought it was very easy to see this requirement and immediately began to write code. If your first instinct is the same, you may wish to see the end of the article with patience.
Thoughts of most students:
1. First, create a main function. The first thing of the main function is to prompt the user to enter the three sides of the triangle and then obtain the user's input (assuming that the user's input is an integer ), it is written in C language. This step is basically not a problem (printf and scanf). But if you want to write it in Java, many students will encounter problems immediately, java5.0 and earlier versions are not easy to obtain users' input.
Comments:The program created in this way can only test all business logic manually, and the program can only be a DOS interface version. If you want to use a graphical interface for input, you have to write all the code.
2. The business processing process is shown in a flowchart as follows:
3. C language code:
- # Include <stdio. h>
- Void main ()
- {
- Int A, B, C;
- Printf ("Please enter three INTEGER :");
- Scanf ("% d", & A, & B, & C );
- If (0 <A & A <200 & 0 <B & B <200 & 0 <C & C <200)
- {
- If (a + B> C & A + C> B & C + B>)
- {
- If (A = B & B = C & A = C) // a judgment can be omitted here.
- {
- Printf ("1 is an equilateral triangle ");
- }
- Else
- {
- If (A = B | B = c | A = C)
- {
- Printf ("2 is an isosceles triangle ");
- }
- Else
- {
- If (A * A + B * B = C * c | A * A + C * c = B * B | B * B + C * c = *)
- {
- Printf ("3 is a right triangle ");
- }
- Else
- {
- Printf ("4 is a normal triangle ");
- }
- }
- }
- }
- Else
- {
- Printf ("5 cannot form a triangle ");
- }
- }
- Else
- {
- Printf ("6 some sides do not meet the limit ");
- }
- }
Comments: The program created in this way can only test all business logic manually, and this program can only be a DOS interface version. If you want to use a web or graphical interface for input, you have to write all the code.