@ pankaj joshi: Hi ... The following code will do it for you. Go through
the code, execute it, if u dont get the logic revert back to me.
// code begins..............
#include<stdio.h>
#define MAX 10000
void factorialof(int);
void multiply(int);
int length = 0;
int fact[MAX];
int main(){
int num;
int i;
printf("Enter any integer number : ");
scanf("%d",&num);
fact[0]=1;
factorialof(num);
printf("Result is : ");
for(i=length;i>=0;i--){
printf("%d",fact[i]);
}
return 0;
}
void factorialof(int num){
int i;
for(i=1;i<=num;i++){
multiply(num);
}
}
void multiply(int num){
long i,r=0;
int arr[MAX];
for(i=0;i<=length;i++){
arr[i]=fact[i];
}
for(i=0;i<=length;i++){
fact[i] = (arr[i]*num + r)%10;
r = (arr[i]*num + r)/10;
//printf("%d ",r);
}
if(r!=0){
while(r!=0){
fact[i]=r%10;
r= r/10;
i++;
}
}
length = i-1;
}
// code terminates......
On 17 May 2012 11:12, Prem Krishna Chettri <[email protected]> wrote:
> Yes U are Correct.. in Such cases the Compiler itself has overcome ( or
> tried to overcome) the architecture limitations to some extends but what
> will happen if U need say 128 or 256 or more values??
>
> Again U hv your compiler restricted limitation right? So that what I
> am talking about is.. Write a code which accept all the value yet fits in
> 8/16/32 bit compiler and architecture...
>
> Yes I am talking more optimistic way as I am talking about embedded
> technologies.But there will be one limitationl which can't be overcome and
> that is the maximum registers available.
>
> When your code finally runs it will be using assembly language.. where the
> operation like R1=M[SP+8] kinda operation happens.. Now the more advance
> processors will hv this register of 32 bit ( Guess intel i7 ships 64 bit as
> well). but these registers are limited..unlike memories in heap.
>
>
> So if M talking about 8085/6 processor, there are 8/16 of these 8 bit
> registers.. So the max U can really force your calculation to have is
> 8*8=64 bit operation or 8*16=128 bit operation. singly.
>
> but with latest intel i7's it can go much higher.. that why these
> processors are expensive :)
>
>
> On Thu, May 17, 2012 at 10:41 AM, pankaj joshi <[email protected]>wrote:
>
>> @Victor: - hi i have tried with 2 array but the complexity will increases
>> as the n grows.
>> So can you please share your code, if you have done this
>> already.
>> @Prem:- Actually the ALU does only 32 bit calculation, but if i am
>> telling about VC++(or can be any compiler)
>> support the calulation long long (8 byte , 64 bit), then
>> the compiler will do the calculation such a way that
>> the result of the calculation save in two memory locations.
>> ( i think, please correct me if i am wrong),
>> @don: - Don actually the problem wants the full value not the truncated
>> double values .
>> but anyway thanks for exp(log(n)*n) :)
>>
>> On Thu, May 17, 2012 at 4:52 AM, Don <[email protected]> wrote:
>>
>>> How about
>>>
>>> exp(log(n)*n);
>>>
>>> Don
>>>
>>> On May 14, 10:58 pm, pankaj joshi <[email protected]> wrote:
>>> > Hi All,
>>> >
>>> > I have written a program to find out n^n(n power n),
>>> >
>>> > long long unsigned int power(int n, int i)
>>> > {
>>> > if(i == 1)
>>> > {
>>> > return n;}
>>> >
>>> > else
>>> > {
>>> > if(i%2 != 1)
>>> > {
>>> > long long unsigned int mul;
>>> > mul = power(n,i/2);
>>> > return mul*mul;}
>>> >
>>> > else
>>> > {
>>> > return (power(n,i-1)*n);
>>> >
>>> > }
>>> > }
>>> > }
>>> >
>>> > This program is working fine for power(15,15), but it is overflow for
>>> > power(16,16), as long long unsigned int is 2^64.
>>> >
>>> > Please tell me how to store the values more than 2^64,
>>> > i had thing to store in array.
>>> > Please suggest me .
>>> >
>>> > thanks ..
>>> >
>>> > --
>>> > Regards,
>>> >
>>> > Pankaj Kumar Joshi
>>>
>>> --
>>> 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?hl=en.
>>>
>>>
>>
>>
>> --
>> Regards,
>>
>> Pankaj Kumar Joshi
>>
>> --
>> 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?hl=en.
>>
>
> --
> 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?hl=en.
>
--
*Piyush Khandelwal**
*Contact: 91-8447229204
--
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?hl=en.