js 대수 더하기, 빼 기, 곱 하기 (정수) 연산

3352 단어 js
	//  
	function jia(a, b) {
		// a,b  zong  
		var zong = [String(a), String(b)];
		//  fen  
		var fen = [];
		// a,b       
		zong = getMax(zong[0], zong[1]);
		// zong             
		zong[0] = zong[0].split('');
		zong[1] = zong[1].split('');
		//   0  
		var jialing;
		//            
		if(!(zong[0].length == zong[1].length)) {
			//  0
			jialing = new Array(zong[0].length-zong[1].length+1).join('0');
			// 0  zong[1]  
			zong[1] = jialing.split('').concat(zong[1]);
		}
		//          
		var next = 0;
		//           
		for(var i=(zong[0].length-1); i>=0; i--) {
			//  
			var he = Number(zong[0][i]) + Number(zong[1][i]) + next;
			//            
			fen.unshift(he%10);
			//                 ,         
			next = Math.floor(he/10);
			//                              
			if(i == 0 && !(next==0)) {
				fen.unshift(next);										
			}						
		}
		//            
		var result = fen.join('');
		//     
		return result;
	}

	//  
	function jian(a, b) {
		var zong = [String(a), String(b)];
		var fen = [];
		zong = getMax(zong[0], zong[1]);
		if(zong.length == 3) {
			alert("    ");
			return false;
		}
		zong[0] = zong[0].split('');
		zong[1] = zong[1].split('');
		var jialing;
		if(!(zong[0].length == zong[1].length)) {
			jialing = new Array(zong[0].length-zong[1].length+1).join('0');
			zong[1] = jialing.split('').concat(zong[1]);
		}
		var next = 0;
		for(var i=(zong[0].length-1); i>=0; i--) {
			var cha = Number(zong[0][i]) - Number(zong[1][i]) - next;
			next = 0;
			if(cha<0) {
				cha = cha + 10;
				next = 1;
			}
			fen.unshift(cha%10);					
		}
		var result = fen.join('');
		if(result[0] == 0) {
			result = shanchuling(result);
		}
		return result;	
	}

	//  
	function cheng(a, b) {
		var zong = [String(a), String(b)];
		var fen = [];
		zong = getMax(zong[0], zong[1]);

		zong[0] = zong[0].split('');
		zong[1] = zong[1].split('');
		//  b   ,          
		for(var j=(zong[1].length-1); j>=0; j--) {
			var next = 0;
			var fentemp = []; 
			var jialing = '';
			//  a       
			for(var i=(zong[0].length-1); i>=0; i--) {
				var ji = Number(zong[0][i]) * Number(zong[1][j]) + next;
				fentemp.unshift(ji%10);
				next = Math.floor(ji/10);
				if(i == 0 && !(next==0)) {
					fentemp.unshift(next);										
				}
			}
			//    0
			jialing = new Array((zong[1].length-(j+1))+1).join('0');
			fentemp.push(jialing);			
			fen[j] = fentemp.join('');				
		}
		//        
		var cishu = fen.length;
		for(var k=1; kresult[1][i]) {
					result[0] = a;
					result[1] = b;
					return result;
				}
				if(result[0][i]b.length) {
			return result;				
		}
	}

	//          0
	function shanchuling(result) {
		//          0,         0
		if(result == 0) {
			result = 0;
			//       
			return result;
		}
		//         
		result = result.split('');	
		//      
		var hebing = result.length;
		for(var j=0; j

좋은 웹페이지 즐겨찾기