当前位置:网站首页>C language decimal number to binary number

C language decimal number to binary number

2022-07-23 08:10:00 Live up to youth and Su

 

#include <stdio.h> 

#define N 8  // Fixed digits 

int main()

{
	int arr[N] = {0};// Initialize the array to 0( When the number of digits is not enough , Will output 0 fill )	
	int i;	
	int n;	
	printf(" Please enter an integer :\n");	
	scanf("%d",&n);	
	for (i = N-1; i >=0; i--)  // Assign values to the array from back to front 
	{	
		arr[i] = n % 2;	
		n /= 2;
	}	
	printf(" This value is converted into binary number and output as (8 position ):");	
	for (i = 0; i <= N - 1; i++)	
		printf("%d",arr[i]);		
	return 0;
}

原网站

版权声明
本文为[Live up to youth and Su]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207222216208245.html