C打印 大数的 阶乘
6000甚至10000,都可以,但大于6000,就开始滚屏了。。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
int i,j,*f,tmp,c=0;
long int n,bits;
const double PI=2*asin(1.0),E=exp(1.0);
scanf("%ld",&n);
bits=(long)ceil(n*(log10(n)-log10(E))+log10(2*PI*n)/2);
printf("there are %ld digits\n%ld!=",bits,n);
f=(int*)calloc(bits,sizeof(int));
f[0]=1;
for(i=2;i<=n;i++){
for(j=0;j<bits;j++){
tmp=f[j]*i+c;
c=tmp/10;
f[j]=tmp%10;
} }
for(i=bits-1;i>=0;i--) printf("%d",f[i]);
printf("\n");
return 0;
}
相关文档:
1. wprintf
Q : sizeof(wchar_t) = ?
A : 随编译器不同。(所以:在需要跨平台的时候尽量不用wchar_t) vc : sizeof(wchar_t) = 2;
Q: 在vc中,为什么直接使用wprintf(L"测试1234")会没有结果
A: 没有设置好locale,这样做
setlocale(LC_ALL ,
"
chs
"
);
wprintf(L
"
%s
"
,L
......
一.环境的安装
下载安装包,Google上搜索php+apache+sql的安装包并安装。
二.扩展编程
针对在PHP环境下掉用C编程(c程序编译的dll),主要有以下两种方式。
1.利用ATL构建DLL组件,然后再PHP里面直接调用,调用方法 ......
#include<stdlib.h>
#include<iostream>
#include<string.h>
using namespace std;
int main(void)
{
FILE *fp, *fp2;
char buf[1024*300];
fp = fopen("in.txt", "rb");
fp2 = fopen("out.txt", "wb+");
fseek(fp, 0, SEEK_END);
int iLen ......
函数名: stpcpy
功 能: 拷贝一个字符串到另一个
用 法: char *stpcpy(char *destin, char *source);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
& ......