c语言转二进制
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<string.h> 4 #include <time.h> 5 //#include<math.h> 6 // 7 //#include<iostream> 8 //using namespace std; 9 10 #include<stdio.h> 11 12 char temp[50] = ""; 13 14 void f(int n) 15 { 16 int a; 17 char b[5]; 18 if(n) 19 f(n/2); 20 else 21 return; 22 a = n%2; 23 printf("%d",a); 24 sprintf(b,"%d",a); 25 strcat(temp,b); 26 } 27 28 int main() 29 { 30 int n; 31 while(1) 32 { 33 memset(temp,0,50); 34 scanf("%d",&n); 35 if(n<0) 36 break; 37 if(n==0) 38 printf("0"); 39 f(n); 40 printf("\n"); 41 printf("temp:%s\n",temp); 42 } 43 return 0; 44 }