scanf怎么用?

如题所述

scanf()与printf函数一样,都被声明在头文件stdio.h里,因此在使用scanf函数时要加上#include <stdio.h>。

scanf函数的作用是按照变量在内存的地址将变量值存进去。

例如:

#include <stdio.h>int main(void){

    int a,b,c;

    printf("Give me the value of a,b,c seperated with whitespaces:\n");

    scanf("%d%d%d",&a,&b,&c);

    printf("a=%d,b=%d,c=%d\n",a,b,c);

    return 0;

}

扩展资料:

如果scanf中%d是连着写的如“%d%d%d”,在输入数据时,数据之间不可以用逗号分隔,只能用空白字符(空格或tab键或者回车键)分隔——“2 (空格)3(tab) 4” 或 “2(tab)3(回车)4”等。若是“%d,%d,%d”,则在输入数据时需要加“,”,如“2,3,4”。

参考资料来源:百度百科-scanf

温馨提示:答案为网友推荐,仅供参考
相似回答