有这样一段C++程序。如何在输出的二进制前面补0呢?使得所有输出的二进制数都为16位。 5
#include<iostream.h>#include<stdio.h>inttemp=0;intarray[65536]={0};intstr[]={0};inti=...
#include <iostream.h>
#include <stdio.h>
int temp = 0;
int array[65536] = {0};
int str[] = {0 };
int i = 0;
int k=15;
void fun_1(int n)
{
if(n<2)
{str[i++]= n;
cout<<str[i-1]; }
if(n>=2)
{
fun_1(n/2);
str[i++] = (n%2);cout<<str[i-1];
}
}
double Calculator (double u, double x)
{
for (int i = 0; i < 65535; i++)
{
x = u * x * (1 - x);
temp = x*10000;
fun_1(temp);
cout<< str[i] <<endl;
}
return 1;
}
int main()
{
Calculator (4, 0.6);
return 0;
} 展开
#include <stdio.h>
int temp = 0;
int array[65536] = {0};
int str[] = {0 };
int i = 0;
int k=15;
void fun_1(int n)
{
if(n<2)
{str[i++]= n;
cout<<str[i-1]; }
if(n>=2)
{
fun_1(n/2);
str[i++] = (n%2);cout<<str[i-1];
}
}
double Calculator (double u, double x)
{
for (int i = 0; i < 65535; i++)
{
x = u * x * (1 - x);
temp = x*10000;
fun_1(temp);
cout<< str[i] <<endl;
}
return 1;
}
int main()
{
Calculator (4, 0.6);
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询