当前位置:网站首页>Find the original code, inverse code and complement of signed numbers [C language]

Find the original code, inverse code and complement of signed numbers [C language]

2022-07-07 08:45:00 Study silently every day

/* Signed binary number inverse and complement */

#include<stdio.h>
int main()
{ 
 	int n,d,i,j;
	printf(" Please enter the number of digits of the signed binary number :");
	scanf("%d",&n);
	int a[n],b[n],c[n];
	printf(" Please enter the binary number :");

	for(int i=0;i<n;i++)   // Enter binary number  
	{
		scanf("%d",&d);
		a[i]=d;
	}
	
	if(a[0]==0)
	{
		printf(" The original code of the binary number = Inverse code = Complement code :");   // The original code of a positive number , Inverse and complement are the same  
		for(int i=0;i<n;i++)   //
		{
			printf("%d",a[i]);
		}
	}
	
	else if(a[0]==1)
	{
		printf(" The original code of the binary number :");   // Print the original code of negative numbers  
		for(i=0;i<n;i++)   //
		{
			printf("%d",a[i]);
		}printf("\n");
		for(i=1;i<n;i++)               // Judge whether the sign bit of the number is 1, Others are 0
		{
			if(a[i]!=0)
			break;
			}	
		if(i==n){                                  // If it is , Only original code and inverse code 
		printf(" This number has only original code and complement , There is no inverse code \n");
		printf(" The complement of this number is :");
		for(j=0;j<n;j+
原网站

版权声明
本文为[Study silently every day]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070604097278.html