You are not logged in. Please login at www.codechef.com to post your questions!

×

FACTORIAL OF NUMBER

What m doing wrong in this 10 lines?

`#include<iostream[link text][1]>using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t,n,res=1,i;
    cin >> t;
    while(t!=0){
        cin>>n;
        if(n>=0){
            for(i=1;i<=n;i++) {
                res=res*i;
            }
            cout<<res<<endl;
            res=1;
        }

        t--;
    }
    return 0;

}`

asked 15 Dec '18, 01:12

samrat_007's gravatar image

2★samrat_007
1
accept rate: 0%


How big can n be?

For a C++ int data type, the maximum positive value it can hold is 2147483647 on most modern compilers.

If n >= 13, n! is larger than C++ max int. So you may need to rethink the data structure you use.

Good luck!

link

answered 16 Dec '18, 00:08

sbatten1969's gravatar image

3★sbatten1969
583
accept rate: 16%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×196

question asked: 15 Dec '18, 01:12

question was seen: 52 times

last updated: 16 Dec '18, 00:08