Auto commit
This commit is contained in:
		
							parent
							
								
									c573ab7540
								
							
						
					
					
						commit
						e8fd54dc02
					
				
							
								
								
									
										91
									
								
								高精度.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								高精度.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,91 @@ | ||||
| ### 高精度加法 | ||||
| 
 | ||||
| ```c | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| 
 | ||||
| int main(){ | ||||
| 	char str1[200], str2[200], result[201] = {0}; | ||||
| 	int i, j, k = 0, t = 0; | ||||
| 
 | ||||
| 	scanf("%s %s", str1, str2); | ||||
| 	i=strlen(str1)-1; | ||||
| 	j=strlen(str2)-1; | ||||
| 	while(i >= 0 || j >= 0){ | ||||
| 		if(i >= 0) t+=str1[i--]-48; | ||||
| 		if(j >= 0) t+=str2[j--]-48; | ||||
| 		result[k++] = t%10+48; | ||||
| 		t /= 10; | ||||
| 	} | ||||
| 	if(t != 0){ | ||||
| 		result[k++] = t+48; | ||||
| 	} | ||||
| 	 | ||||
| 	for(i=k-1;i>=0;i--){ | ||||
| 		putchar(result[i]); | ||||
| 	} | ||||
| 	puts(""); | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| ### 高精度乘法 | ||||
| 
 | ||||
| ```c | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| 
 | ||||
| int main(){ | ||||
| 	char str1[200], str2[200], temp[200],result[1000] = {0}; | ||||
| 	int i, j, k, t; | ||||
| 	scanf("%s%s", str1, str2); | ||||
| 	 | ||||
| 	j=strlen(str2)-1; | ||||
| 	 | ||||
| 	while(j>=0){ | ||||
| 		k=0; | ||||
| 		for(i=strlen(str1)-1;i>=0;i--){ | ||||
| 			t = k + strlen(str2)-1-j; | ||||
| 			result[t+1] += (result[t] + (str1[i]-48)*(str2[j]-48))/10; | ||||
| 			result[t] = (result[t] + (str1[i]-48)*(str2[j]-48))%10; | ||||
| 			k++; | ||||
| 		} | ||||
| 		j--; | ||||
| 	} | ||||
| 	k+=strlen(str2)-1; | ||||
| 	while(result[k]==0) k--;//È¥µô¿Õ¸ñ | ||||
| 	 | ||||
| 	while(k>=0){ | ||||
| 		putchar(result[k] + 48); | ||||
| 		k--; | ||||
| 	}  | ||||
| 	puts(""); | ||||
| 
 | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| ### 高精度减法 | ||||
| 
 | ||||
| ```c | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| ### 高精度乘法 | ||||
| 
 | ||||
| ```c | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user