You are not logged in. Please login at www.codechef.com to post your questions!

×

[closed] small factorial...wrong ans

i dont know the cases where it fails but i have checked it even for 100 and other smaller numbers it is showing the correct ans but when i try to submit it everytime showing wrong ans dont know why . somebody pls help you can chk the following code yourself in your compiler. I KNOW THE CODE IS A BIT COMPLEX.MAY BE THERE IS A BETTER WAY TO SOLVE THE SAME QUESTION BUT I AM NOT GETTING THAT CASE ON WHICH IT FAILS SO PLS HELP.

include<stdio.h>

int g(int c);

int main()

{int a,x,k,te,b,z,m,j,e,c,d,i,t;

int f[1000];

scanf("%d",&a);

for(i=0;i<a;i++)

{ scanf("%d",&t);

k=t;

d=g(t);

for(b=0;b<d;b++)

 { f[b]=t%10;

   t=t/10;

 }

te=0;

m=0;

x=0;

if(k>1)

{

while(--k)

{ while(d--)

{

  x=f[m]*k+te;

  f[m]=x%10;

  te=x/10;

  m++;

  }

 while(te)

{

 f[m]=te%10;

 te=te/10;

 m++;

 }

   d=m;

 e=m-1;

 m=0;

 te=0;

 }

for(j=e;j>=0;j--)

{printf("%d",f[j]);}

printf("\n");

}if(k==1)

printf("1");

}

return 0;}

int g(int c)

{int a=0;

while(c)

{a=a+1;

c=c/10;

}

return a;}

asked 20 Jan '15, 21:27

ychhabra60's gravatar image

6★ychhabra60
111
accept rate: 0%

closed 21 Jan '15, 18:46

betlista's gravatar image

3★betlista ♦♦
16.9k49115225

1

Please post your code properly using proper blocks or ideone code is always better. :)

(20 Jan '15, 21:33) damn_me3★

The question has been closed for the following reason "Duplicate Question - http://discuss.codechef.com/questions/62340/small-factorial-wrong-answer You do not need to ask multiple times, just edit your previous question" by betlista 21 Jan '15, 18:46


Check here: https://ideone.com/CwES8i

The output formatting is wrong.

link

answered 21 Jan '15, 15:50

ketanhwr's gravatar image

6★ketanhwr
1.9k31844
accept rate: 15%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×196
×33

question asked: 20 Jan '15, 21:27

question was seen: 773 times

last updated: 21 Jan '15, 18:46