×

# doubt in small factorials question

WHY THIS CODE ISNT WORKING

# include <iostream>

using namespace std;

int main() { int t,x,i,fact[100],temp; cout<<"input"; cin>>t; if(t>0&&t<=100) {for(i=0;i<t;i++) {temp="1;" cin="">>x; for(int k=1;k<=x;k++) { temp=temp*k;

  }
fact[i]=temp;


} cout<<"output"; for(int j=0;j<t;j++) { cout<<"\n"<<fact[j]; } } return 0; }

2★coder_ag
112
accept rate: 0%

 0 Hello, Thanks for posting the question. It appears that you are new to Codechef so welcome to the community. I checked the code, and edited out some basic lines like - i) There is no need for an "Input" prompt. The input will be given by the judging system and whatever you print our additionally will be marked as output. Since the output format is very strict, try and stick to that. ii) No need to check if the test cases are within limits or not. The boundaries giving in the problem statement will always be valid. And it is the tester's responsibility to ensure that the input is within limits. I have submitted a valid code here after editing your code - https://www.codechef.com/viewsolution/19283050 iii) Test the code with the sample input. Once you are able to get the sample output, design your own sample cases that test boundary conditions. For example, try taking 100 factorial, or zero factorial. In your case, the logic fails at anything more than 25, since the variable temp is an 'int' datatype which can hold at max data upto 2*10^9. So you need a different logic. As described here - https://www.geeksforgeeks.org/factorial-large-number/ I hope that helps. Warm Regards and all the best in your journey! Ruddra answered 20 Jul '18, 15:53 124●5 accept rate: 7% most of the question i encountered here needs to store large numbers.. so does we always have to apply this logic (20 Jul '18, 17:39) coder_ag2★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×316
×196
×181
×33

question asked: 20 Jul '18, 13:51

question was seen: 128 times

last updated: 20 Jul '18, 17:39