因素计划 [英] FACTORIAL PROGRAM

查看:54
本文介绍了因素计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下程序来计算阶乘:


#include< stdio.h>

#include< iostream.h>

void main()

{

int i,n;

long int p = 1; //或长双p = 1;对于指数结果,我不想要b $ b bb<<""输入数字" ;;

cin>> ; n;

if(n == 0)

{

cout<<" 1" ;

}

其他

{

for(i = n; i> = 1; i-- )

{

p = p * i;

}

}

cout< ;<" Factorial ="<< p;

}


但它可以通过阶乘12来将结果显示为整数。怎么

我可以改进它,以便它可以显示结果为一个INTEGER至多
阶乘100或更多?


谢谢。

解决方案

Umesh写道:

....


但它可以使用阶乘12来将结果显示为整数。

如何改进它以便它可以将结果显示为INTEGER,直至
阶乘100或更多?



您将需要使用多精度算术库。

http://gmplib.org/


Umesh说:


i编写了以下程序来计算阶乘:


#include< stdio.h>

#include< iostream.h>



C或C ++中没有这样的标题。


void main()



主要的声明器不正确,无论是C还是C ++。


{

int i ,n;

long int p = 1; //或长双p = 1;对于指数结果,我不想要b $ b。



''不想要。''是一个语法错误,无论是C还是C ++。


cout<<""输入号码" ;;



如果你不采取措施确保不这样做,cout是未定义的 - 在
C和C ++中都可以。


cin>> n;



cin相同。


if(n == 0)

{

cout<<" 1" ;

}

其他

{

for(i = n; i> = 1; i-- )

{

p = p * i;

}

}

cout< ;<" Factorial ="<< p;

}


但它可以通过阶乘12来将结果显示为整数。



真的吗?它不会在这里编译。未终止的字符常量。


如何

我可以改进它以便它可以将结果显示为INTEGER,直到

factorial 100或更多?



#include< stdio.h>


int main(无效)

{

put(" 100!=");

printf(" 933262154439441526816992388562667004907159 6826438162");

printf(" 146859296389521759999322991560894146397615 65182862536" ;);

printf(" 979208272237582511852109168640000000000000 00000000000 \ n");

返回0;

}

编写自己的例程来处理非常大的整数,甚至使用别人的'b
'对初学者来说可能是一个非常棘手的任务。我建议你专注于重新学习基础知识,这次正确,并且

保存整数冒险以供日后使用。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。


Umesh写道:


i编写了以下程序来计算阶乘:


#include< stdio.h>

#include< iostream.h>



这不是标准C.


void main()



这是一个众所周知的不 - 标准的不要做C.为C.


{

int i,n;

long int p = 1; //或长双p = 1;对于指数结果,我不想要b $ b。



这是一个语法错误,说明为什么//评论是坏消息,Quillan,

在usenet帖子中。
< blockquote class =post_quotes>
cout<<"输入号码" ;;



这是'尝试将未声明的整数变量

换成char *金额,这在C中是非法的至少有两个原因,

或C ++,这意味着你误读了地图并向右转,而是在最后一个交叉路径上留下了
左。


但它可以使用阶乘12来将结果显示为整数。

如何改进它以便它可以将结果显示为INTEGER,直至
阶乘100或更多?



使用可以处理更大数字的整数类型,例如由off-topic-here bignum包提供的

。 />

-

是鸟吗?这是一架飞机?不,它是: http://hpl.hp.com/conferences/ juc2007 /

Uenet上没有元音的元素。


Hewlett-Packard Limited注册办事处:Cain Road,Bracknell,

注册号:690597英格兰伯克斯RG12 1HN


i wrote the following program to calculate factorial:

#include<stdio.h>
#include<iostream.h>
void main()
{
int i,n;
long int p=1; // or long double p=1; for exponential result which I
don''t want.
cout<<"Enter No. ";
cin>>n;
if(n==0)
{
cout<<"1" ;
}
else
{
for(i=n;i>=1;i--)
{
p=p*i ;
}
}
cout<<"Factorial = "<<p;
}

But it works upto factorial 12 to display result as an integer. How
can I improve it so that it can display the result as an INTEGER upto
factorial 100 or more?.

THANK YOU.

解决方案

Umesh wrote:
....

But it works upto factorial 12 to display result as an integer. How
can I improve it so that it can display the result as an INTEGER upto
factorial 100 or more?.

You will need to use a Multiple Precision Arithmetic Library.

http://gmplib.org/


Umesh said:

i wrote the following program to calculate factorial:

#include<stdio.h>
#include<iostream.h>

No such header, in either C or C++.

void main()

Incorrect declarator for main, in either C or C++.

{
int i,n;
long int p=1; // or long double p=1; for exponential result which I
don''t want.

''don''t want.'' is a syntax error, in either C or C++.

cout<<"Enter No. ";

If you don''t take steps to ensure otherwise, cout is undefined - in both
C and C++.

cin>>n;

Same for cin.

if(n==0)
{
cout<<"1" ;
}
else
{
for(i=n;i>=1;i--)
{
p=p*i ;
}
}
cout<<"Factorial = "<<p;
}

But it works upto factorial 12 to display result as an integer.

Really? It won''t compile here. Unterminated character constant.

How
can I improve it so that it can display the result as an INTEGER upto
factorial 100 or more?.

#include <stdio.h>

int main(void)
{
puts("100! =");
printf("933262154439441526816992388562667004907159 6826438162");
printf("146859296389521759999322991560894146397615 65182862536");
printf("979208272237582511852109168640000000000000 00000000000\n");
return 0;
}

Writing your own routines for handling very large integers, or even
using someone else''s, can be quite a tricky task for a beginner. I
suggest you focus on re-learning the basics, properly this time, and
save your integer adventures for later.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


Umesh wrote:

i wrote the following program to calculate factorial:

#include<stdio.h>
#include<iostream.h>

That''s not standard C.

void main()

That''s a well-know not-Standard DON''T DO THAT for C.

{
int i,n;
long int p=1; // or long double p=1; for exponential result which I
don''t want.

That''s a syntax error illustrating why // comments are Bad News, Quillan,
in usenet postings.

cout<<"Enter No. ";

And that''s either an attempt to shift an undeclared integer variable
by a char* amount, which is illegal in C for at least two reasons,
or C++, meaning that you misread the map and turned right, instead
of left, at the last crosscorridors.

But it works upto factorial 12 to display result as an integer. How
can I improve it so that it can display the result as an INTEGER upto
factorial 100 or more?.

Use an integer type that can cope with bigger numbers, such as supplied
by an off-topic-here bignum package.

--
Is it a bird? It is a plane? No, it''s: http://hpl.hp.com/conferences/juc2007/
There'' no hortage of vowel on Uenet.

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN


这篇关于因素计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆