예제 #1
0
파일: two.cpp 프로젝트: Nexfer/DlinAriph
	veryLong veryLong::operator*(veryLong n1)
	{
		veryLong n;
		if (!binary)
		{
			turn(&number);
			if (&number != &n1.number)
				turn(&n1.number);
			if (((znak=='+')&&(n1.znak=='+'))||((znak=='-')&&(n1.znak=='-')))
			{
				n.number = mul(&number,&n1.number);
				n.znak='+';
			}
			else
			{
				n.number = mul(&number,&n1.number);
				n.znak='-';
			}
			n.lenght = strlenn(&n.number);
			n.binary=binary;
			turn(&number);
			if (&number != &n1.number)
				turn(&n1.number);
			turn(&n.number);
		}
		else
		{
			n.number = mulb(&number,&n1.number,lenght,n1.lenght,&n.lenght);
			n.binary=binary;
		}
		return n;
	}
예제 #2
0
unsigned char *stepenb(unsigned char **numberOne,unsigned char **numberTwo,int lenghtFirst,int lenghtSecond,int *lenghtSumm)
{
	int i,lenght,lenghtSt;
	unsigned  char *firstNumber,*st,*incr;
	firstNumber = (unsigned char*)malloc(lenghtFirst+2);
	st = (unsigned char*)malloc(block);
	incr = (unsigned char*)malloc(4);
	st[0]=1;
	incr[0]=1;
	lenghtSt=1;
	for (i=0;i<lenghtFirst;i++)
		firstNumber[i]=(*numberOne)[i];
	lenght=lenghtFirst;
	while(1)
	{
		if (cmpb(&st,&(*numberTwo),lenghtSt,lenghtSecond) == 2)
			break;
		firstNumber = mulb(&firstNumber,&(*numberOne),lenght,lenghtFirst,&lenght);
		st=summb(&st,&incr,lenghtSt,1,&lenghtSt);
	}
	*lenghtSumm=lenght;
	return firstNumber;
}
예제 #3
0
int main(int argc, char *argv[])
{
    char *inputFirst,*inputSecond,*inputThird;
    FILE *output;
    int lenghtFirst,lenghtSecond,i,binary,module,lenghtModule;
    unsigned char *numberOne,*numberTwo,*ostatok,*numModule;
	unsigned char znak1,znak2,znak3;
	char znak;
	if (argc < 5 )
	{
		printf("\nEnter correct parameters\n");
		return 0;
	}
	if (argc == 7)
	{
		binary=1;
		module=1;
		inputThird=argv[6];
		lenghtModule = readb(&numModule,inputThird);
	}
	if (argc == 6)
	{
		if (strcmp(argv[5],"-b") == 0)
		{
			binary=1;
			module=0;
		}
		else
		{
			binary=0;
			module=1;
			inputThird=argv[5];
			lenghtModule = readd(&numModule,inputThird,&znak3);
		}
	}
	if (argc < 6)
	{
		binary=0;
		module=0;
	}
    
    
	inputFirst =argv[1];
    inputSecond=argv[3];
    
    if(!binary)
    {
        
        output = fopen(argv[4],"w");
    }
    else
    {
        output = fopen(argv[4],"wb");
    }
    
	znak=argv[2][0];
	switch(znak)
	{
		case '+' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((znak1=='+')&&(znak2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((znak1=='-')&&(znak2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
				if ((znak1=='+')&&(znak2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((znak1=='-')&&(znak2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=summb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '-' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((znak1=='+')&&(znak2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((znak1=='-')&&(znak2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
				if ((znak1=='+')&&(znak2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((znak1=='-')&&(znak2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=subb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '*' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				if (((znak1=='+')&&(znak2=='+'))||((znak1=='-')&&(znak2=='-')))
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
				}
				else
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=mulb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '/' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				if (((znak1=='+')&&(znak2=='+'))||((znak1=='-')&&(znak2=='-')))
				{
					fprintf(output,"%s",divv(&numberOne,&numberTwo,&ostatok));
				}
				else
				{
					fprintf(output,"-%s",divv(&numberOne,&numberTwo,&ostatok));
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lenghtFirst);
				turnb(&numberTwo,lenghtSecond);
				numberOne=divvb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst,&ostatok,&lenghtSecond);
				turnb(&numberOne,lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '%' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				divv(&numberOne,&numberTwo,&ostatok);
				fprintf(output,"%s",ostatok);
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lenghtFirst);
				turnb(&numberTwo,lenghtSecond);
				divvb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst,&ostatok,&lenghtSecond);
				turnb(&ostatok,lenghtSecond);
				fwrite(ostatok,lenghtSecond,1,output);
				free(ostatok);
			}
			break;
            
		case '^' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				numberOne=stepen(&numberOne,&numberTwo,&znak1);
				turn(&numberOne);
				if (znak1=='+')
					fprintf(output,"%s",numberOne);
				else
					fprintf(output,"-%s",numberOne);
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=stepenb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
		default:
			break;
	}
    
    fclose(output);
    
	if (module)
	{
		if(!binary)
		{
			output = fopen(argv[4],"w");
			divv(&numberOne,&numModule,&ostatok);
			fprintf(output,"%s",ostatok);
		}
		else
		{
			output = fopen(argv[4],"wb");
			turnb(&numberOne,lenghtFirst);
			turnb(&numModule,lenghtModule);
			divvb(&numberOne,&numModule,lenghtFirst,lenghtModule,&lenghtFirst,&ostatok,&lenghtModule);
			turnb(&ostatok,lenghtModule);
			fwrite(ostatok,lenghtModule,1,output);
		}
		fclose(output);
	    
	}
    return 0;
}
예제 #4
0
int main(int argc, char *argv[])
{
    FILE *output;
    char *inputFirst,*inputSecond,*inputThird;
    int lengthFirst,lengthSecond,i,binary,module,lengthModule;
    unsigned char *numberOne,*numberTwo,*remainder,*numModule;
	unsigned char sign1,sign2,sign3;
	char sign;
	if (argc < 5 )
	{
		printf("\nEnter correct parameters\n");
		return 0;
	}
    if (argc < 6)
	{
		binary=0;
		module=0;
	}
    if (argc == 6)
	{
		if (strcmp(argv[5],"-b") == 0)
		{
			binary=1;
			module=0;
		}
		else
		{
			binary=0;
			module=1;
			inputThird=argv[5];
			lengthModule = readd(&numModule,inputThird,&sign3);
		}
	}
	if (argc == 7)
	{
		binary=1;
		module=1;
		inputThird=argv[6];
		lengthModule = readb(&numModule,inputThird);
	}
	
	inputFirst =argv[1];
    inputSecond=argv[3];

    if(!binary)
    {

        output = fopen(argv[4],"w");
    }
    else
    {
        output = fopen(argv[4],"wb");
    }

	sign=argv[2][0];
	switch(sign)
	{
		case '+' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((sign1=='+')&&(sign2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((sign1=='-')&&(sign2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
				if ((sign1=='+')&&(sign2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((sign1=='-')&&(sign2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=summb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '-' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((sign1=='+')&&(sign2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((sign1=='-')&&(sign2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
				if ((sign1=='+')&&(sign2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((sign1=='-')&&(sign2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=subb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '*' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				if (((sign1=='+')&&(sign2=='+'))||((sign1=='-')&&(sign2=='-')))
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
				}
				else
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=mulb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '/' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				if (((sign1=='+')&&(sign2=='+'))||((sign1=='-')&&(sign2=='-')))
				{
					fprintf(output,"%s",divv(&numberOne,&numberTwo,&remainder));
				}
				else
				{
					fprintf(output,"-%s",divv(&numberOne,&numberTwo,&remainder));
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lengthFirst);
				turnb(&numberTwo,lengthSecond);
				numberOne=divvb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst,&remainder,&lengthSecond);
				turnb(&numberOne,lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '%' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				divv(&numberOne,&numberTwo,&remainder);
				fprintf(output,"%s",remainder);
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lengthFirst);
				turnb(&numberTwo,lengthSecond);
				divvb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst,&remainder,&lengthSecond);
				turnb(&remainder,lengthSecond);
				fwrite(remainder,lengthSecond,1,output);
				free(remainder);
			}
			break;

		case '^' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				numberOne=degree(&numberOne,&numberTwo,&sign1);
				turn(&numberOne);
				if (sign1=='+')
					fprintf(output,"%s",numberOne);
				else
					fprintf(output,"-%s",numberOne);
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=degreeb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;
		default:
			break;
	}

    fclose(output);

	if (module)
	{
		if(!binary)
		{
			output = fopen(argv[4],"w");
			divv(&numberOne,&numModule,&remainder);
			fprintf(output,"%s",remainder);
		}
		else
		{
			output = fopen(argv[4],"wb");
			turnb(&numberOne,lengthFirst);
			turnb(&numModule,lengthModule);
			divvb(&numberOne,&numModule,lengthFirst,lengthModule,&lengthFirst,&remainder,&lengthModule);
			turnb(&remainder,lengthModule);
			fwrite(remainder,lengthModule,1,output);
		}
		fclose(output);
	    
	}
    return 0;
}