C++编写程序,输入一个正整数输出其二进制形式,通过函数调用实习。
2个回答
展开全部
//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
void dfs(int k){
if(k>1) dfs(k/2);
printf("%d",k%2);
}
void main(void){
int n;
printf("Input n(int)...\nn=");
scanf("%d",&n);
printf("The binary of %d is ",n);
dfs(n);
printf("\n");
}
#include "stdio.h"
void dfs(int k){
if(k>1) dfs(k/2);
printf("%d",k%2);
}
void main(void){
int n;
printf("Input n(int)...\nn=");
scanf("%d",&n);
printf("The binary of %d is ",n);
dfs(n);
printf("\n");
}
2014-06-05
展开全部
#include<stdio.h>
#include<string.h>
void Exchange( char* , int n );
int main( ){
char num[30];
int n;
scanf("%d", &n );
Exchange( num, n );
for( int i = strlen( num )-1 ; i >= 0 ; i-- )
printf("%c", num[i] );
return 0;
}
void Exchange( char* num, int n ){
int i = 0;
while( n != 0 ){
num[i] = (n%2+'0');
n /= 2;
i++;
}
num[i]= '\0';
}
#include<string.h>
void Exchange( char* , int n );
int main( ){
char num[30];
int n;
scanf("%d", &n );
Exchange( num, n );
for( int i = strlen( num )-1 ; i >= 0 ; i-- )
printf("%c", num[i] );
return 0;
}
void Exchange( char* num, int n ){
int i = 0;
while( n != 0 ){
num[i] = (n%2+'0');
n /= 2;
i++;
}
num[i]= '\0';
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |