?? multiply.c
字號:
#include <stdio.h>#include <stdlib.h>#define M 1.0e+256#define N 33554432Lunsigned int multiply(unsigned int n, double *result, unsigned int highest);void print(double *outdata, unsigned int highest);int main(int argc, char *argv[]){ unsigned int i = 0, n =0, highest = 0; double *data; data = malloc(N); *data = 1.0; if(argc != 2) { printf("The Parameter is wrong\n"); exit(1); } else { while(*(argv[1] + i) != '\0') { if((*(argv[1] + i) <= 0x39) && (*(argv[1] + i) >= 0x30)) i++; else { printf("The Parameter is wrong\n"); exit(1); } } } n = atoi(argv[1]); printf("The %d! = ", n); for(i = 2; i <= n; i++) highest = multiply(i, data, highest); print(data, highest); free(data); exit(0);}unsigned int multiply(unsigned int n, double *result, unsigned int highest){ double tmp; double carrier = 0.0; int i; for(i = 0; i <= highest; i++) { tmp = n; tmp *= *(result + i); tmp += carrier; if(tmp > 1.0e+256) { carrier = tmp / M; *(result + i) = tmp - carrier*M; } else { carrier = 0.0; *(result + i) = tmp; } } if(carrier) *(result + (++highest)) = carrier; return highest;}void print(double *outdata, unsigned int highest){ FILE *Buff; unsigned char data[32]; unsigned char *index; unsigned int index1; if(highest == 0) printf("%.18e", *(outdata + highest)); else { Buff = fopen("./out", "w+"); fprintf(Buff,"%.18e", *(outdata + highest)); fclose(Buff); Buff = fopen("./out", "r"); fread(data, sizeof(unsigned char), 32, Buff); printf("%.22s",data); index = data + 22; index1 = atoi(index); printf("%u", index1 + highest*256); fclose(Buff); remove("./out"); } printf("\n");}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -