2007-08-31 18:33




2007-08-31 18:41
2007-08-31 18:55
2007-08-31 18:55
2007-09-01 16:20
在c++里 int这类自然数据类型是不能是不能重新定义int类的,要根据不同的程序目的自己编写,下面有个求阶乘的例子做参考:
#include<iostream>
using namespace std;
#define max 200
void ditui(int a[],int k)
{
int m=a[0]; //m代表计算结果的位数
int *b=new int[m+1];
int i,j;
int r;
int carry;
for(i=1;i<=m;i++) b[i]=a[i];
for(j=1;j<k;j++)
{
for(carry=0,i=1;i<=m;i++)
{
r=(i<=a[0]?a[i]+b[i]:a[i])+carry;
a[i]=r%10;carry=r/10;
}
if(carry) a[++m]=carry;
}
delete [] b;
a[0]=m;
}
void write(int* a,int k)
{
int i;
cout<<k<<"!=";
for(i=a[0];i>0;i--)
cout<<a[i];
cout<<endl;
}
void main()
{
int a[max],n,k;
cout<<"输入n的值:"<<endl;
cin>>n;
a[0]=1;a[1]=1;
write(a,1);
for(k=2;k<=n;k++)
{
ditui(a,k);
write(a,k);
}
}

2007-09-05 14:59
2007-09-08 13:05
If your int fits 32-bit int/unsigned int, you can use the built-in type 'int' or 'unsigned int';
If your int fits 64-bit int/unsigned int, you can use type 'long long' or 'unsigned long long';
If your int exceeds 64-bit, you need a 'BigInt' class. Java has a built-in BigInt class, C++ does not.

2007-09-08 17:29
用字符串接收,用函数atol转换.
2007-09-13 16:31