コード例 #1
0
//*****(F-3)*****	
largeInt addl(largeInt ia1,largeInt ia2) // ADDITION
{
	largeInt iresult,ik1,ik2;
	largeNum result,a1,a2;	
	if(equal_to_zero(ia1) && equal_to_zero(ia2))
	{
		iresult.sign=0;
		iresult.len=1;
		iresult.line[0]='0';
		return(iresult);	
	}
	else
	{
		
		if( (ia1.sign==0 && ia2.sign==1) || (ia1.sign==1 && ia2.sign==0) )
		{
			ik1=absl(ia1);
			ik2=absl(ia2);
			iresult=subl(ik1,ik2);
			if(greaterthan(ik1,ik2)==1)
			{
			
				iresult.sign=ia1.sign;
			}
			else
			{
			
				iresult.sign=ia2.sign;
			}
		}
		else if(ia1.sign==1 && ia2.sign==1)
		{
			IntToNum(ia1,&a1);
			IntToNum(ia2,&a2);
			result=add_pos(a1,a2);
			NumToInt(result,&iresult);
			iresult.sign=1;
		}
		else
		{
			IntToNum(ia1,&a1);
			IntToNum(ia2,&a2);
			result=add_pos(a1,a2);
			NumToInt(result,&iresult);
		}
		if(equal_to_zero(iresult))
		{
			iresult.sign=0;
			iresult.len=1;
			iresult.line[0]='0';
		} 
		return iresult;
	}
}
コード例 #2
0
//*****(F-4)*****
largeInt multl(largeInt ia1,largeInt ia2)// For multiplying any +ve/-ve numbers
{
	largeInt iresult;
	largeNum multiplicand,multiplier,result,temp,a1,a2;
	int k,i,j,n;
	if(equal_to_zero(ia1) || equal_to_zero(ia2))
	{
		iresult.sign=0;
		iresult.len=1;
		iresult.line[0]='0';
		return(iresult);	
	}
	else
	{
		IntToNum(ia1,&a1);
		IntToNum(ia2,&a2);
		if(Ngreaterthan(a1,a2)==1)
		{
			multiplicand=a1;
			multiplier=a2;
		}
		else
		{
			multiplicand=a2;
			multiplier=a1;
		}
		k=multiplier.len-1;
		for(i=k;i>=0;i--)
		{
			n=multiplier.line[i];
			if(i==k)            // multiplication for the left most term of multiplier
			{
				result=add_n_times(multiplicand,n);
			}
			else
			{
				temp=add_n_times(multiplicand,n);
				temp.len+=(k-i);  //decides number of zeroes to be appended
				for(j=1;j<=k-i;j++)
		    			temp.line[(temp.len)-j]=0;
	  	        	result=add_pos(result,temp);
			}
		}
		if((multiplicand.sign==0 && multiplier.sign==1) || (multiplicand.sign==1 && multiplier.sign==0))
			result.sign=1;
		else
			result.sign=0;
		NumToInt(result,&iresult);
		return iresult;
	}
}
コード例 #3
0
ファイル: xt7-2.c プロジェクト: hclife/linux-bash
int main()
{void greater_than_zero(float,float);
 void equal_to_zero(float,float);
 void smaller_than_zero(float,float);
 float a,b,c;
 printf("input a,b,c:");
 scanf("%f,%f,%f",&a,&b,&c);
 printf("equation: %5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c);
 disc=b*b-4*a*c;
 printf("root:\n");
 if (disc>0)
  {
   greater_than_zero(a,b);
   printf("x1=%f\t\tx2=%f\n",x1,x2);
  }
 else if (disc==0)
  {equal_to_zero(a,b);
   printf("x1=%f\t\tx2=%f\n",x1,x2);
  }
 else
  {smaller_than_zero(a,b);
   printf("x1=%f+%fi\tx2=%f-%fi\n",p,q,p,q);
  }
 return 0;
}
コード例 #4
0
//*****(F-2)
largeInt subl(largeInt ia1, largeInt ia2) // For substracting any +ve/-ve numbers
{
	int i,k,d;
	largeNum result,a1,a2;
	largeInt iresult;
	if(equal_to_zero(ia1) && equal_to_zero(ia2))
	{
		iresult.sign=0;
		iresult.len=1;
		iresult.line[0]='0';
		return(iresult);	
	}
	else
	{
		IntToNum(ia1,&a1);
		IntToNum(ia2,&a2);
		if(a1.sign==1 && a2.sign==0)
		{
			result=add_pos(a1,a2);
			result.sign=1;
			NumToInt(result,&iresult);
			return(iresult);
		}
		else if(a1.sign==0 && a2.sign==1)
		{
			result=add_pos(a1,a2);
			result.sign=0;
			NumToInt(result,&iresult);
			return(iresult);
		}
		else 
		{
				if(greaterthan(ia1,ia2)==1)		
		   		{		
			
					d=a1.len-a2.len;
					shift(&a2,d);
					k=a1.len-1;
					for(i=k;i>=0;i--)
					{
						if(a1.line[i]<a2.line[i])
						{
							result.line[i]=(a1.line[i]+10)-a2.line[i];
							a2.line[i-1]++;
						}
						else
						{
							result.line[i]=a1.line[i]-a2.line[i];
						}
					}
				
					result.len=a1.len;
					if(a1.sign==0&&a2.sign==0)
						result.sign=0;
					else
						result.sign=1;
					rem_all_zeros_from_left(&result);
					NumToInt(result,&iresult);
					if(equal_to_zero(iresult))
					{
						iresult.sign=0;
						iresult.len=1;
						iresult.line[0]='0';
					} 
					return(iresult);
				}
				else
				{
					d=a2.len-a1.len;
					shift(&a1,d);
					k=a2.len-1;
					for(i=k;i>=0;i--)
					{
						if(a2.line[i]<a1.line[i])
						{
							result.line[i]=(a2.line[i]+10)-a1.line[i];
							a1.line[i-1]++;
						}
						else
						{
							result.line[i]=a2.line[i]-a1.line[i];
						}
					}
					result.len=a2.len;
					if(a1.sign==0&&a2.sign==0)
						result.sign=1;
					else
						result.sign=0;
					rem_all_zeros_from_left(&result);
					NumToInt(result,&iresult);
					if(equal_to_zero(iresult))
					{
						iresult.sign=0;
						iresult.len=1;
						iresult.line[0]='0';
					} 
					return(iresult);
				}
		 	
		}
	}
}