C语言printf 和 scanf 用法

printf

int a = 1;
long b = 1234567890;
float c = 1.56;
double d = 1234567.343;
int e = 12;
char ch = 'a'; //字符
char chs[] = "abc";//字符串 ,因为c语言中没有字符串这种数据类型,只有char字符类型,在C语言中所谓的字符串其实是char数组,数组最后一个元素加上“\0",表示字符串结束,这是一种字符串的表达方式。

printf("%d", a);
printf("%ld", b);
printf("%f", c);
printf("%lf", d);
printf("%0", e); //8进制
printf("%0X", e); //16进制
printf("%#0X", e); //16进制 带0X
printf("%0x", e); //16进制
printf("%#0x", e); //16进制 带0x
printf("%c", ch);
printf("%s", chs);

scanf

#include<stdio.h>   
#include<stdlib.h>
int main(int argc,char**argv) {
    printf("Hello,Linux.\n");

    int a = 1 * 2;
    int b = 012;
    int c = 0x12;

    char d[] = "abc";
    printf("%i\n",a);
    printf("%d\n",b);
    printf("%d\n",c);
    printf("%s\n",d);

    char i[12];
    scanf("%s", &i);
    printf("您输入了一个字符串:%s\n", i);

    char ch;
    while((ch=getchar()) != '\n') {
            continue;
    }

    int e;
    scanf("ok%d", &e);
    printf("e = %d\n", e);

    while((ch=getchar()) != '\n') {
            continue;
    }


    int j, k;
    scanf("%d %d", &j, &k);
    printf("j = %d, k = %d\n", j, k);
    return 0;
}
posted @ 2016-06-25 15:59  final_day  阅读(737)  评论(0编辑  收藏  举报