| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

已结贴   问题点数：20  回复次数：6

/*    c6-17.c    */
#include<stdio.h>
int main()
{
int i, j = 1, k=1,t;
int len = 0;
int a[50];
for (i = 2;i <= 10;i++)
j = j * i;
for (i = 0;k == 0;i++)
{
t = j % 10;
a[i] = t;
k = j / 10;
t = k;
len = len + 1;
}
for(i=len;i>=1;i--)
printf("%d", a[i]);
return 0;
}

得分:15

```#include <stdio.h>

int main()
{
int i, j = 1;
int len = 0;
int a[50];
for (i = 2;i <= 10;i++)
j = j * i;

for (i = 0;j != 0;i++)
{
a[i] = j % 10;
j = j / 10;
len = len + 1;
//printf("i=%d,a[i]=%d,j=%d,len=%d\n",i,a[i],j,len);
}

printf("j=");
for(i=len-1;i>=0;i--)
printf("%d", a[i]);
return 0;
}```
得分:0

得分:5

得分:0

得分:0

```#include <stdio.h>
#include <stdbool.h>

bool factorial( unsigned n, char out[], size_t out_size )
{
if( out_size < 2 )
return false;
out[out_size-2] = 1;
char* pbeg = out+out_size-2;

for( unsigned i=1; i<=n; ++i )
{
unsigned carry = 0;
for( char* p=out+out_size-2; p>=pbeg; --p )
{
carry = carry + (*p * i);
*p = carry%10;
carry /= 10;
}
for( ; carry!=0; carry/=10 )
{
if( pbeg == out )
return false;
*--pbeg = carry%10;
}
}

for( char* p=pbeg; p!=out+out_size-1; ++p )
out[p-pbeg] = *p + '0';
out[out+out_size-1-pbeg] = '\0';
return true;
}

int main( void )
{
char buf[50];

if( factorial(0,buf,sizeof buf) )
printf( "0! = %s\n", buf );

if( factorial(1,buf,sizeof buf) )
printf( "1! = %s\n", buf );

if( factorial(10,buf,sizeof buf) )
printf( "10! = %s\n", buf );

if( factorial(40,buf,sizeof buf) )
printf( "40! = %s\n", buf );

if( factorial(41,buf,sizeof buf) )
printf( "41! = %s\n", buf );
}```
得分:0

• 7
• 1/1页
• 1