贺老师教学链接 C语言及程序设计初步 本课讲解
用printf函数输出
#include <stdio.h> int main() { printf("Hello World!\n"); printf("Welcome\nto\nBeijing!\n"); return 0; }
#include <stdio.h> int main(){ printf("%d\n", 1234); printf("%6d\n", 1234); printf("%o\n", 1234); printf("%x\n", 1234); printf("%X\n", 1234); printf("%u\n", -1234); return 0; }
#include <stdio.h> int main(){ printf("%f\n", 1234.56); printf("%10.3f\n", 1234.56); printf("%e\n", 1234.56); printf("%E\n", 1234.56); printf("%g\n", 1234.567); printf("%g\n", 1234567.89); return 0; }
#include <stdio.h> int main() { int a, b, c; scanf("%d %d", &a, &b); c = a + b; printf("%d + %d = %d\n", a, b, c); printf("%f + %f = %f\n", a, b, c); return 0; }
#include <stdio.h> int main() { int a, b, c; scanf("%d %d", &a, &b); c = a + b; printf("%d + %d = %d\n", a, b); printf("%d + %d = %d\n", a, b, c, a); return 0; }