Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

FCTRL unexpected output

$
0
0

Here is my code for http://www.codechef.com/problems/FCTRL problem.

The problem is that my program is giving correct output upto factorial 17 but number after 17 gives wrong output. I have tried to code it thrice from the scratch but the problem remains the same. Can you please tell me what is the reason?

My code is:-

include<iostream>

using namespace std;

int main()

{

long long int arr[200],ai=0,t,ti=1,n,m=0,x=0,ni,temp=0,n2;

cin>>t;

for(ti=1;ti<=t;ti++)

{

ai=0;

m=0;

cin>>n;

n2=n-1;

for(ni=n2;ni>1;ni--)

{

 while(n>0)

 {

    arr[ai]=n%10;

    n=n/10;

    ai++;

    m++;

 }

 temp=0;

 for(ai=0;ai<m;ai++)

 {
    x=ni*arr[ai]+temp;

    arr[ai]=x%10;

    temp=x/10;

 }

 if(temp>0)

 {

     arr[ai]=temp%10;

     temp=temp/10;

     m++;

     ai++;

 }

}

/////////////////


for(ai=m-1;ai>=0;ai--)

{

  cout<<arr[ai];

}

cout<<"\n";

}

}


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>