well to find the factorial of very large numbers u can use linkedlist
or some other datastructure to hold the digits of the product and
manipulate the linked list......because the size of the linked list can
grow at runtime. I guess this will solve ur problem...
u need a linked list because the size of the integers on computers is
fixed and can hold up certain numbers (max int) so we need to tackle
that also


#include<iostream.h>
#include<conio.h>
#include<process.h>

#define null 0

struct node {
   int value;
   node* next;
   node() {
      next=null;
   }
};

void adjustList(node* p) {
   node* count=p;
   int temp;
   int carry=0;
   while(1) {
     count->value += carry;
     temp = count->value;
     count->value = temp%10;
     carry = temp/10;
     if(count->next==null)
        break;
     count = count->next;
   }
   while(carry!=0) {
     count->next = new node();
     count = count->next;
     count->value = carry%10;
     carry /= 10;
   }
}

//prints the factorial recurssively this reduces the range of the
factorial

void printFactorial(node* p) {
   if(p==null)
      return;
   printFactorial(p->next);
   cout<<p->value;
}

void main() {
   clrscr();
   int num;
   node* head = new node();
   node* count;
   cout<<"Enter the number whose factorial is to be found: ";
   cin>>num;
   if(num<0) {
      cout<<"Negative number factorial not defined";
      exit(1);
   }

  for(int i=0;i<=num;i++) {
     count=head;
     while(1) {
       if(i==0) {
          count->value=1;
          break;
       }
       else {
         count->value *= i;
         if(count->next==null)
            break;
         count=count->next;
       }
     }
    adjustList(head);
   }
   printFactorial(head);
   getch();
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to