戴维营第二天上课总结
今天珊哥讲解了进制的转换, 以及C语言的32个关键字, 然后我自己尝试算了一道进制的转换题目
二进制转换十进制
1010 = 1*2^3+0*2^2+1*2^1+0*2^0 = 10
十进制转二进制
10 = 10/2 余数0
5/2 余数1
2/2 余数0
1/2 余数1
1 #include <stdio.h> 2 3 int main(int argc, const char * argv[]) 4 { 5 int a = sizeof(int); 6 printf("a = %d\n", a); 7 8 char b = sizeof(char); 9 printf("b = %d\n", b); 10 11 long c = sizeof(long); 12 printf("c = %ld\n", c); 13 14 float d = sizeof(float); 15 printf("d = %f\n", d); 16 17 double e = sizeof(double); 18 printf("e = %lf\n", e); 19 20 short f = sizeof(short); 21 printf("f = %d\n", f); 22 23 int i,j; 24 int n = 4 ; //设定图形的行数 25 26 for( i=1; i <= n; i++ ) //重复输出图形的n行 27 { 28 for( j=1; j <= 2*n-i; j++ ) //重复输出图形一行中的每个字符 29 if(j <= i-1) 30 printf(" "); //输出前面的空格 31 else 32 printf("*"); //输出后面的*号 33 34 printf("\n"); 35 } 36 37 float g = 2.3; 38 printf("g = %.4f\n", g); 39 40 return 0; 41 }
输出结果:
a = 4
b = 1
c = 8
d = 4.000000
e = 8.000000
f = 2
*******
*****
***
*
g = 2.3000
Program ended with exit code: 0