zl程序教程

您现在的位置是:首页 >  其它

当前栏目

问题 1477: 字符串输入输出函数

问题 函数 字符串 输入输出
2023-06-13 09:18:28 时间

题目描述 编写函数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

#include <iostream>
# include<cstring>
# include<stdio.h>
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",b);

    return 0;
}