+ 3
Look this c++ code.
https://code.sololearn.com/cVAE0HBy6QJg/?ref=app It's working properly till 12! but after that it's not. Why? As per me there is no logical error in it. if you find one, please tell.
9 Réponses
+ 6
@Rame
you have to increase memory size of your variable and not function.
keep int function()
change unsigned long long int y;
+ 6
no don't change function datatype, it won't have any affect.
you need to increase storage memory of int variable by using,
unsigned long long int y;
where y is your variable storing value of factorial.
+ 6
@rame
i am not really sure about that, but you can try both cases.
+ 4
You hit the maximum value int can store. Replace 'int' with 'long long' and it will go further. However, you will hit that maximum after a few more numbers.
+ 4
There must be some corrections in your code
https://code.sololearn.com/cmPHgzp3RAnV/?ref=app
+ 3
@john wells #include <iostream>
using namespace std;
long long fact(long long x) {
long long y,i,prod=1;
cin>>y;
for(i=1;i<=y;i++)
{
prod*=i;
}
return prod;
}
int main()
{
long long y;
cout<<fact(y);
return 0;
}
is this correct?
+ 3
Please check it.
+ 3
@infinity The code you posted is public?
I guess you forgot to do so.
+ 2
@dhruv garg
do i need to change my Function datatype even when I use use recursion( like one I used in my program) ?