[Cpp-Programming] Re: problem during runtime
Integer is overflowing. take double and modified ur code accordingly.
On Jun 3, 2:02 pm, Deepak <deepakkushwah2...@gmail.com> wrote:
> hi
> there is a problem of finding the factorial of no upto 100 now we
> don't have any variable to store that amount of data
> so i'm considering an array of 200 elements inwhich each element
> contains the digits of final ans
> for example 720 will be stored as a[0]=0 a[1]=2 a[2]=7
> given below is it's program but it is not giving the correct ans
> after 10
> help me if u can find any bug in this program
>
> #include<iostream>
> using namespace std;
> int main()
> {
> cout<<"enter the no of test cases:"<<endl;
> int t;
> int num;
> cin>>t;
> int a[200]; //array to accomodate the digits of the
> factorial
> for(int i=0;i<t;i++) //this loop will run for all the
> test cases
> {
> a[0]=1; //initialising the array with
> a[0]=1 and rest all the elements 0
> for(int i=1;i<=199;i++)
> {
> a[i]=0;
> }
> int temp=0;
> int m=1; //carry the no. of elements in
> the array occupied during factorial computation
> cout<<"enter the no"<<endl;
> cin>>num; // the no. of which we have to
> find the factorial
> for(int j=1;j<=num;j++)
> {
> for(int k=0;;k++)
> {
> int x=a[k]*j+temp;
> a[k]=x%10;
> temp=x/10;
> if(temp==0 && a[k+1]==0) break;
>
> if(a[k+1]==0)m++;
> }
> }
> for(int i=m-1;i>=0;i--)
> {
> cout<<a[i];
> }
> cout<<endl;
> }
> system("pause");
>
>
>
>
>
>
>
> }
--
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to cpp-programming@googlegroups.com.
To unsubscribe from this group, send email to cpp-programming+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cpp-programming?hl=en.
0 Comments:
Post a Comment
<< Home