#include<stdio.h>
void main (void)
{
int a=1;
int i;
for (i=1;i<=35;a=a*i)
{printf ("%d!=%d\n",i,a);
i++;
}
}
哪里错了 啊???
第1个回答 2019-06-01
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
int main(int argc, char **argv){
if(argc != 2){
printf("%s N, N=[1,MAX]\n", argv[0]);
return 0;
}
struct timeval now, tv, diff;
gettimeofday(&now, NULL);
int n = atoi(argv[1]);
if(n < 1){
printf("error N > 0\n");
return 0;
}
#define NUM 500000
int a[NUM+1];
int i, j, h;
memset(a, 0, sizeof(a));
h = 1;
a[0] = 1;
for(i = 1; i <= n; i++){
for(j = 0; j < h; j++){
a[j] = a[j] * i;
}
for(j = 0; j < h; j++){
a[j+1] = a[j+1] + a[j]/10;
a[j] = a[j]%10;;
if(a[j+1] > 0 && j + 1 == h){
h++;
}
}
if(h > NUM){
printf("value too max\n");
return -1;
}
}
gettimeofday(&tv, NULL);
diff.tv_sec = tv.tv_sec - now.tv_sec;
diff.tv_usec = tv.tv_usec - now.tv_usec;
if(diff.tv_usec < 0){
diff.tv_usec += 1000000;
diff.tv_sec -= 1;
}
printf("h:%d\n", h);
int flag = 0;
int m = 0;
int z = 0;
for(i = 0; z == 0 && i < NUM ;i++){
if(a[i]){
z = i;
}
}
for(i = NUM; i >= z; i--){
if(a[i] > 0){
flag = 1;
}
if(flag ){
m++;
printf("%d", a[i]);
}
if(m > 0 && m % 100 == 0){
printf("\n");
}
}
printf(" x 10^%d", z);
printf("\n");
printf("h:%d time:%lds %ldus\n", h, diff.tv_sec, diff.tv_usec);
return 0;
}
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
int main(int argc, char **argv){
if(argc != 2){
printf("%s N, N=[1,MAX]\n", argv[0]);
return 0;
}
struct timeval now, tv, diff;
gettimeofday(&now, NULL);
int n = atoi(argv[1]);
if(n < 1){
printf("error N > 0\n");
return 0;
}
#define NUM 500000
int a[NUM+1];
int i, j, h;
memset(a, 0, sizeof(a));
h = 1;
a[0] = 1;
for(i = 1; i <= n; i++){
for(j = 0; j < h; j++){
a[j] = a[j] * i;
}
for(j = 0; j < h; j++){
a[j+1] = a[j+1] + a[j]/10;
a[j] = a[j]%10;;
if(a[j+1] > 0 && j + 1 == h){
h++;
}
}
if(h > NUM){
printf("value too max\n");
return -1;
}
}
gettimeofday(&tv, NULL);
diff.tv_sec = tv.tv_sec - now.tv_sec;
diff.tv_usec = tv.tv_usec - now.tv_usec;
if(diff.tv_usec < 0){
diff.tv_usec += 1000000;
diff.tv_sec -= 1;
}
printf("h:%d\n", h);
int flag = 0;
int m = 0;
int z = 0;
for(i = 0; z == 0 && i < NUM ;i++){
if(a[i]){
z = i;
}
}
for(i = NUM; i >= z; i--){
if(a[i] > 0){
flag = 1;
}
if(flag ){
m++;
printf("%d", a[i]);
}
if(m > 0 && m % 100 == 0){
printf("\n");
}
}
printf(" x 10^%d", z);
printf("\n");
printf("h:%d time:%lds %ldus\n", h, diff.tv_sec, diff.tv_usec);
return 0;
}
第2个回答 2013-07-23
数太大了,用int不行