Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,963 questions

51,905 answers

573 users

How to calculate factorial for big numbers with long double in C++

1 Answer

0 votes
#include <iostream>
#include <iomanip>

using std::cout;
using std::endl;

int main()
{
	long double n = 1.0, factorial = 1.0;

	cout.precision(0);           
	cout.setf(std::ios::left, std::ios::fixed);
  
	 for (int i = 0; i < 21; i++) {
		factorial *= n;
		n++;
		cout.width(13);            
		cout << factorial << endl;
	}


	return 0;
}


/*
run:

1
2
6
24
120
720
5040
40320
362880
3.6288e+06
3.99168e+07
4.79002e+08
6.22702e+09
8.71783e+10
1.30767e+12
2.09228e+13
3.55687e+14
6.40237e+15
1.21645e+17
2.4329e+18
5.10909e+19

*/

 



answered May 26, 2018 by avibootz

Related questions

2 answers 203 views
1 answer 165 views
2 answers 125 views
1 answer 163 views
1 answer 178 views
2 answers 171 views
...