Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Small factorial: help

$
0
0

i have run this code in my compiler it work fine till its upper limit as per given in the question. But codechef gives it wrong every time. please any body help. the link to the question given below

http://www.codechef.com/problems/FCTRL2

include<stdio.h>
int fact(int p[],int q,int t){

t--;
int i,temp=0,x;

for(i=0;i<q;i++){

x=p[i]*t+temp;

p[i]=x%10;

temp=x/10;

}

while(temp>0){

q++;

p[q-1]=temp%10;

temp/=10;

}

if(t>1){

fact(p,q,t);

}
else{

printf("\n");
for(i=q-1;i>=0;i--){

printf("%d",p[i]);
}
}

}

int count(int x){

int p[200],t=x,q=0,i,j;

if(x==1){

printf("%d",x);

}

else{

for(i=0;t>0;i++){

p[i]=t%10;

t/=10;

q++;

}

fact(p,q,x);
} }

int main(){

int t,i,j,a[100];

scanf("%d",&t);

for(i=0;i<t;i++){

scanf("%d",&a[i]);

}

for(i=0;i<t;i++){

count(a[i]);


}
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>