topic
Write a program, whose function is to: a floating-point input from the keyboard (with three digits after the decimal point), and then outputs the integer and fractional part of the number.
Sample input: 123.456
Sample Output: 123 456
Code 1
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int a,b;
scanf("%d.%d",&a,&b);
printf("%d %03d\n",a,b);
return 0;
}
Code 2
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char a[100];
gets(a);
int s,i;
s=strlen(a);
for(i=0;i<s;i++)
{
if(a[i]=='.')cout<<" ";
else cout<<a[i];
}
return 0;
}
result
to sum up
The first method for solving the problem is tricky, and the second a wider application conditions.