class=”markdown_views prism-atom-one-light”>
Write the code as follows
#include
using namespace std;
int main()
{
int a; //integer type
a=1; //Assign
cout<<"This is a:"<< a<<endl; //output statement
float b; //floating point
b=2.3; //Assign
cout<<"This is b:"<< b<<endl;
float c,d;
c=a/2; // divide a by 2, assign to c
cout<<"This is c:"<< c<<endl;
d=b/2; // divide b by 2, assign it to d
cout<<"This is d:"<< d<<endl;
return 0;
}
Analysis
Pay attention to the output results of the floating-point variables c and d. Because a is an integer variable, the result of a/2 is 0, and the decimal part is removed. Only keep the integer part (not Rounding);
and b is a floating-point variable, the result of b/2 is 1.15, and the decimal part is preserved.
Output
[This series is only a very basic introduction, suitable for readers who do not need to understand deeply , thank you for reading~]