Home > Back-end >  For help
For help

Time:03-08

Judge arbitrary triangle type, programming requirements:
1) prompt "input the three sides of the triangle,", if you can't continue to input boundary value of triangle, use cycle control, loop condition is applied to the logical operation of special rules,
(2) the application of simple the if () ~ statement judge type of triangle, and the output, such as, the triangle is a right Angle (or isosceles or equilateral or arbitrary triangles), if condition is applied to the logical operation of special rules,
(3) for the first time after the calculation, giving prompt "whether or not to continue to judge other types of triangle [Y/N]? Continue to enter, enter a Y or Y, end the program, a nested loop structure,

CodePudding user response:

Reference:
 # include & lt; stdio.h> 

Int main ()
{
Int a, b, c;
Char s='Y'

While (s=='Y' | | s=='Y') {
While (1) {//input
Printf (" input the three sides of the triangle (positive integer) : ");
If (the scanf (" % d % d % d ", & amp; A, & amp; B, & amp; C)!=3 | | a & lt; 0 | | b & lt; 0 | | c & lt; 0 {
While ((getchar ())!='\ n');
Printf (" \ n input error! \n");
continue;
} the else
If (a + bPrintf (" \ n input side cannot constitute a triangle! \n");
continue;
} the else
break;
}
If (a==b | | a==c | |==b, c) {//judgment triangle type
If (a==b & amp; & B==c & amp; & A==c) {
Printf (" \ n input side of an equilateral triangle \ n ");
} else {
Printf (" \ n input side of an isosceles triangle \ n ");
}
}
The else
If (a * * b=a + b=c * c | | a * c==b + c * * b | | b + c * b * c==a * a) {
Printf (" \ n input side of a right triangle \ n ");
} else {
Printf (" \ n input side length for arbitrary triangular \ n ");
}
Printf (" \ n whether continue to judge other triangle type [Y/n]?" );
getchar();
The scanf (" % c ", & amp; S);
}

return 0;
}

CodePudding user response:

Input and output are more reliable, modify the upstairs:
 # include & lt; stdio.h> 

Int main ()
{
Int a, b, c;
Char ch [2]={' Y '};

While (ch [0]=='Y' | | ch [0]=='Y') {
While (1) {//input
Printf (" input the three sides of the triangle (positive integer) : ");
The fflush (stdout);
The rewind (stdin);
If (the scanf (" % d % d % d ", & amp; A, & amp; B, & amp; C)!=3 | | a & lt; 0 | | b & lt; 0 | | c & lt; 0 {
Printf (" \ n input error! \n");
continue;
} the else
If (a + b
Printf (" \ n input side cannot constitute a triangle! \n");
continue;
} the else
break;
}
If (a==b | | a==c | |==b, c) {//judgment triangle type
If (a==b & amp; & B==c & amp; & A==c) {
Printf (" \ n input side of an equilateral triangle \ n ");
} else {
Printf (" \ n input side of an isosceles triangle \ n ");
}
}
The else
If (a * * b=a + b=c * c | | a * c==b + c * * b | | b + c * b * c==a * a) {
Printf (" \ n input side of a right triangle \ n ");
} else {
Printf (" \ n input side length for arbitrary triangular \ n ");
}
Printf (" \ n whether continue to judge other triangle type [Y/n]?" );
The fflush (stdout);
The rewind (stdin);
The scanf (" % s ", ch);
}

return 0;
}
  • Related