#include <stdio.h>
#define N 8 //固定位数
int main()
{
int arr[N] = {0};//将数组初始化为0(位数不满时,将输出0填补)
int i;
int n;
printf("请输入一位整数:\n");
scanf("%d",&n);
for (i = N-1; i >=0; i--) //对数组从后往前赋值
{
arr[i] = n % 2;
n /= 2;
}
printf("该值转化为二进制数输出为(8位):");
for (i = 0; i <= N - 1; i++)
printf("%d",arr[i]);
return 0;
}