题目描述
编写函数GetReal和GetString,在main函数中分别调用这两个函数。在读入一个实数和一个字符串后,将读入的结果依次用printf输出。
两次输入前要输出的提示信息分别是" please input a number:\n”和" please input a string:\n"
输入
无
输出
无
样例输入
9.56 hello
样例输出
please input a number: please input a string: 9.56 hello
很显然,这是一条水题,但注意的是要用printf输出字符串,string是不能直接用printf输出的,我们可以用字符数组输出,也可以用string,不过要用scanf("%s",c.c_str()); printf("%s\n",c.c_str());格式输出。
# include <iostream>
# include<stdio.h>
# include<cstring>
using namespace std;
char a[100];
char b[100];
void GetReal()
{
scanf("%s",&a);
}
void GetString()
{
scanf("%s",&b);
}
int main ()
{
printf("please input a number:\n");
printf("please input a string:\n");
GetReal();
GetString();
printf("%s\n",a);
printf("%s\n",b);
}