[ create a new paste ] login | about

Link: http://codepad.org/D8bopism    [ raw code | output | fork ]

박정욱 - C, pasted on Apr 11:
//수치계산 목 678
//2진수곱셈
#include<stdio.h>

int main()
{
	int i,j;
	int a[4],b[4],c[8]={0};

		printf("        Input A :"); scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]);
		printf("        Input B :"); scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		printf(" A * B = ");

	for(i=3 ; i >=0 ; i--)
	{	
		if(b[i] == 1)
		{	for(j=3; j >=0 ; j--)
			{	c[j+i+1] += a[j];	}
		}
	}

	for(i=7; i>0 ; i--)
	{	while(c[i] > 1)
		{
			c[i-1]++;
			c[i]--;c[i]--;
		}
	}
/*	i=7;
	while(c[i]==0)
	{i--;}*/
	
	for(i=0; i <8;i++)	
	{	printf("%d ",c[i]);}
	printf("\n");
return 0;
}


Output:
1
        Input A :        Input B : A * B = 0 0 0 0 0 0 0 0 


Create a new paste based on this one


Comments: