我正在练习C,编写简单的程序.下面的小程序应该从用户那里获得3个数字并将它们相乘.我的问题是我对我必须使用的变量类型有点困惑.我希望程序采用任何数字,如5,5.673434,99.123等,用它们计算并打印出一个圆形浮点数.我尝试了很多东西但是结果总是错误的.该程序只打印出非常大的数字和令人困惑的字符序列.我会感谢任何建议.谢谢.
#include <stdio.h>
int main()
{
int num1, num2, num3;
printf("Hello! This little programm will execute a few calculations \nafter you've typed in 3 numbers of your choise. \nPlease type in your first number: ");
scanf_s("%f", &num1);
printf("Great. Please choose your second number: ");
scanf_s("%f", &num2);
printf("And the third number please: ");
scanf_s("%f", &num3);
printf("Ok. You want to use %f, %f, %f for your calculation. Press a button begin.\n", num1, num2, num3 );
printf("Multiplication: %.2f", num1 * num2 * num3);
getchar();
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)