C语言编程入门——程序练习(上)
大家能够敲写一下以下的练习代码。看下执行结果,都非常easy。关键要理解。
if:
# include <stdio.h> int main(void) { int i = 1; i = i + 1; if(i>10); i = 1; printf("%d\n", i); return 0; }
if演示样例2:
# include <stdio.h> int main(void) { int i; if (1 > 2) printf("哈哈。\n"); else if (2 > 5) printf("嘿嘿!\n"); else if (2 > 2) printf("skdf"); else i = 1 > 2; printf("i = %d", i); return 0; } /* 总结: 即便有多个表达式成立,也仅仅会运行第一个成立的表达式 */
scanf演示样例1:
# include <stdio.h> int main(void) { int i, j, k; //printf("请输入:i的值"); scanf("%d %d %d", &i, &j, &k); printf("i = %d\nj = %d\nk = %d\n", i, j, k); return 0; }
scanf演示样例2:
# include <stdio.h> int main(void) { int i; char ch; printf("请输入i的值:i="); scanf("%d", &i); printf("结果是:i=%d\n", i); while ((ch=getchar())!='\n') continue; int j; printf("请输入j的值:j="); scanf("%d",&j); printf("结果是:j=%d\n", j); return 0; }
浮点数的存储:
# include <stdio.h> int main(void) { float x = 66.6; printf("x = %f\n", x); return 0; }
bool变量:
# include <stdio.h> int main(void) { bool i; i = true; //1为真。0为假。printf("%d\n", i); return 0; }
取地址符&:
# include <stdio.h> int main(void) { double i = 12314; printf("%#X\n", &i); //以十六进制形式输出变量i的地址 return 0; }