有没有办法将实际输入 int 转换为 double。我不想获取字符串值并使用 isDigit 检查它是 double 还是 int。
int main(void)
{
// Initializing variables
int a,b,c,res;
// Getting input from user
printf("Please enter the sides of triangle");
printf("\nPlease enter side 1:");
scanf("%d",&a);
printf("Please enter side 2:");
scanf("%d",&b);
printf("Please enter side 3:");
scanf("%d",&c);
// Calling function in order to print type of the triangle.
checkTriangle(a,b,c);
}
// A function which decides the type of the triangle and print it
void checkTriangle(int s1, int s2,int s3)
{
// Check the values whether it is triangle or not.
if ((s1 + s2 > s3 && s1 + s3 > s2 && s2 + s3 > s1) && (s1 > 0 && s2 > 0 && s3 > 0))
{
// Deciding type of triangle according to given input.
if (s1 == s2 && s2 == s3)
printf("EQUILATERAL TRIANGLE");
else if (s1 == s2 || s2 == s3 || s1 == s3)
printf("ISOSCELES TRIANGLE\n");
else
printf("SCALENE TRIANGLE \n");
}
else
printf("Triangle could not be formed.");
}
当我用户输入双倍时我想做什么我想给一个消息,你可以输入双倍。有没有办法在不输入字符的情况下做到这一点?