本日开发中出现的问题汇总 | 练习题:将整数转化为二进制。 1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int num,a[20],i=0; 6 printf("Input a number: \n"); 7 scanf("%d",&num); 8 while(num < 0) 9 { 10 exit(0); 11 } 12 while(num != 0) 13 { 14 a[i] = num % 2; 15 num = num / 2; 16 i++; 17 } 18 i--; 19 while(i >= 0) 20 { 21 printf("%d",a[i]); 22 i--; 23 } 24 printf("\n"); 25 return 0; 26 } 作业:三维数组输出 1 #include<stdio.h> 2 3 void print1(char *ptr) 4 { 5 printf("ptr = %s\n",ptr); 6 } 7 8 void print2(char(*ktr)[100]) 9 { 10 for(int i =0;i<2;i++) 11 { 12 printf("ktr[%d]=%s\n",i,*(ktr+i)); 13 } 14 } 15 16 void print3(char(*str)[2][100]) 17 { 18 for(int i=0;i<2;i++) 19 { 20 for(int j=0;j<2;j++) 21 { 22 printf("str[%d][%d}=%s\n",i,j,*(*(str+i)+j)); 23 } 24 } 25 } 26 27 void print4(char **ytr) 28 { 29 int i; 30 for(i = 0; i < 3; i++) 31 { 32 printf("ktr[%d] = %s\n", i, *(ytr + i)); 33 } 34 } 35 36 int main() 37 { 38 char ptr[100]="hello"; 39 char ktr[2][100]={"hello1","hello2"}; 40 char str[2][2][100]={{"hello.3","hello.4"},{"hello.5","hello.6"}}; 41 char *ytr[3] = {"hello1", "hello2", "hello3"}; 42 print1(ptr); 43 print2(ktr); 44 print3(str); 45 print4(ytr); 46 47 return 0; 48 } 结果 |