question:
Continuously input the three sides of the triangle, determine what triangle it is, and output the corresponding statement.
Idea:
- The triangle here must have three sides, input three numbers, and if you want to keep inputting, you can use while(scanf("%d %d %d",&a,&b,&c)); to achieve this.
- The scanf() input function returns the valid number of format characters that you want to match. If I enter three numbers and press Enter, then I enter a loop and the scanf() function will read the characters in the corresponding format until it encounters a blank character and stops reading, such as pressing Enter.
- When scanf("%d",&a), when the a I input is a non-digit, it immediately stops reading and returns 0 (because non-digits are not valid data).
- Then start doing the questions.
- Let’s start with the big categories, triangles and not triangles, use if to implement it.
- Then in the case of triangles, to determine which triangle it is, start with the simplest equilateral one, otherwise it is isosceles, otherwise it is other.
code show as below:
#include <stdio.h>
int main()
{
//输入三个数
int a,b,c;
printf("输入三个数字,表示三角形的边,输入非数字,结束循环\n");
while(scanf("%d %d %d",&a,&b,&c)==3)//每次输入的时候判断,当输入的有效数量(为%d格式的,必须输入数字)等于3时ÿ