Small factorialsProblem code: FCTRL2 |
All submissions for this problem are available.
A tutorial for this problem is available here
You are asked to calculate factorials of some small positive integers.
Input
An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.
Output
For each integer n given at input, display a line with the value of n!
Example
4 1 2 5 3
Sample output:
1 2 120 6
| Date: | 2008-12-01 |
| Time limit: | 1s |
| Source limit: | 2000 |
| Languages: | C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp HASK CAML CLPS PRLG WSPC BF ICK |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

Is it possible to know the reason why my code failed? And would also like to know the input for which it failed. I ran in my PC with the sample input and it worked fine.
The main Issue I am having is the Space management for a particular number.
most probably int will not be able to handle the factorial of 100 or 99
Is it okay if a double is returned?
Can you please tell the reason my code failed? I tested it with the sample input and got the output matching the sample out given.
Can you please tell the reason my code failed? I tested it with the sample input and got the output matching the sample out given.
@manmath - do you get the correct solution for 100?
hey... what wrong with code?
Even I have checked for 100 it give correct result.....
Someone plz give me the link to get the compiler (gcc g ) which codechef uses. My programs run pretty well with Turbo C but here they seem to give compilation error.
Have checked my code like a hundred times but to no use.
from where can i het the correct solution
looks like a lot of us have the same problem. is it because of something like a stack usage limit or something?? admins please help?
seems like a lot of ppl have problem with handling very large nos.
HAHAHAHAHA! Freaking java bigint :|
use warnings;
use strict;
my $fact=1;
my $no;
my $j;
$no=<STDIN>;
while($no)
{
$j=<STDIN>;
while($j)
{
$fact=$fact*$j--;
}
print $fact."\n";
$fact=1;
$no--;
}
Whats wrong with my perl code
>:( this is not gud :( i chked it a lotta times and itz not working :(( here is the code i entered:-
#include<iostream.h>
long int factorial(int n){
if(n<=1){
return(n);
}
else{
n=n*factorial(n-1);
return(n);
}
}
int main(){
int i,*arr,j,fact;
cin>>i;
if(i<=1
@all A tutorial for this problem has been added under the help section.
Mine too. It works perfectly, but it won't accept it.
If it is not being accepted, then it means that there is something wrong with your code. Check the tutorial for more details. http://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/
If factorial is defined as double and returns answer with nill trailing zeroes is it wrong?
Could you be more specific?
@admin:- Actually i meant, factorial which is 1x2x3x4....., what if i store factorial as double (that way it could store larger values).
But sorry admin, i got it, It would give wrong answer that way and i have to store it as an integer.
I finally managed this one. Tutorial helped alot.
Thanks
its running ok on my pc..
then how cud it be wrong
@gaurav You might want to take a look at the tutorial for this problem.
Wow, dealing with BigInts in Java is really annoying.
Can I know why my code
You can try testing it on few
You can try testing it on few large values and calculating the answer using the calculator accessory in your operating system.
im gettin result on my system
@ravi Check your usage of the
@ravi Check your usage of the variable 'j' . You are using it again within the loop where you have used it first.
hi, this is the output of my
The numbers in my previous
No, the output should contain
No, the output should contain one number on one line which. The number on line 'i' is the answer for test case 'i'
hey, the tutorial is really
hey y is my code not accepted
hey y is my code not accepted plzz is there something wrong with the compiler
plzz se to it i tried it a number of times my code is as follows
#include<stdio.h>
#include<conio.h>
void fact(int num);
void main()
{
int t;
static int arr[100];
int i;
clrscr();
printf("nPlz enter the number of test cases: ");
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<t;i++)
{
fact(arr[i]);
}
getch();
}
void fact(int num)
{
int i;
long int fact1=1;
for(i=1;i<=num;i++)
{
fact1=fact1*i;
}
printf("n%ld",fact1);
}
hey there's no wrong in the
hey there's no wrong in the above solution so y is it not accepted
There is a tutorial for this
There is a tutorial for this problem at http://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/ A long integer cannot store something like 100!
i think this will run very
i think this will run very well in python because
there is no limit to size of the numbers
whereas in c++ the maximum we can represent is 4000000000somethin
what if the input is greated
what if the input is greated than 100. for example :
Input : 3
5
200
100
Just let me know the output of the above input.
The input specifications
The input specifications clearly state that the value of n will be 100 at max.
void main() { int
void main()
{
int i,n,fact=1;
scanf("%d",n);
for(i=1;i<=n;I++)
printf("%dn",i);
for(i=1;i<=
print
def fact(n) if n < 100 if n
def fact(n)
if n < 100
if n == 0
1
else
n * fact(n-1)
end
else
puts "Number should less than 100 ..."
end
end
wat do we have to do??????
wat do we have to do??????
how do i store 100 ! in
how do i store 100 ! in java?...
im a school student learning java....guess i'll need a little help at this...im getting the code right but do not know how to store larger values
hi.. My code ran succesfully
hi..
My code ran succesfully on the same compiler on dev cpp...
it gave correct answer even for 100!. But i'm getting wrong answer on code chef...
plz help out.. can u plz have a look at my code also..
sorry.. i got the bug.
sorry..
i got the bug.
My code is showing the wrong
Is your output format in
Yes it was lol i got the
# include
its so simple & easy to
simple & easy to understand
Hey people please check out
hi..i have made the code..it
Yes, your source code length
I have submitted dis
I have submitted dis solution
#include<stdio.h>
#include<conio.h>
int factorial(int val)
{
int i,res=1;
for(i=1;i<=val;i++)
{
res=res*i;
}
return res;
}
void main()
{
int i,n,val,fact;
clrscr();
printf("nPlease enter no of inputs:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("nEnter value:");
scanf("%d",&val);
fact=factorial(val);
printf("%d",fact);
}
getch();
}
on my computer i am getting correct answer, why admin is showing compilation error for my code.
Please read the FAQ. don't
Please read the FAQ. don't use conio.h and getch(). main should return an integer value and your program should end with a return 0
I wrote program which takes
it is working but still it
You need to take input from
You need to take input from stdin and output the results to stdout.
gud eve admin.. i have run my
The first thing you should
The first thing you should have tested your program on was an input of 100.. you obviously haven't.
thnx admin..
(define factorial (lambda (x)
(define factorial
(lambda (x)
(if (> x 1)
(* x (factorial (- x 1)))
1 )))
What's wrong with this scheme code? it gives the correct output for all integers.
can anyone paste ur code
can anyone paste ur code here.........plz
can someone tell me where i
can someone tell me where i am going wrong?
i am generating this output :
50
30414093201713378043612608166064768844377641568960
512000000000000
100
933262154439441526816992388562667004907159682643
816214685929638952175999932299156089414639761565
182862536979208272237582511852109168640000000000
00000000000000
this is the code of my
this is the code of my program
#include<iostream.h>
int main()
{
int t,n,fact[200],i,j,k,c,temp,x;
cin>>t;
for(i=0;i<t;i++)
{
cin>>n;
c=n;
j=0;
while(c>0)
{
fact[j]=c%10;
c=c/10;
j++;
}
while(n>1)
{
n--;
temp=0;
for(k=0;k<j;k++)
{
x=fact[k]*n+temp;
fact[k]=(x%10);
temp=x/10;
if(k==j-1)
{
while(temp>0)
{
fact[j]=temp%10;
temp=temp/10;
j++;
}
break;
}
}
}
for(k=j-1;k>=0;k--)
cout<<fact[k];
}
return 0;
}
Run your code on the sample
Run your code on the sample input and look at what you get as output.
had missed the newline
had missed the newline .....
thnx:)
where can i see the reference
where can i see the reference output to an input that contains all numbers 0-100?
My code seems to run perfect, i want to find the bug!!!
Wow! Check out the ones at
Wow! Check out the ones at the end. Nice problem, never thought it'd be this challenging
check out the zeroes, i mean
check out the zeroes, i mean
Well can any of u plz tell me
Well can any of u plz tell me why this code isnt able to calculate more than 33! the values before 33! are correct......im a bit puzzled....plz help thanks
vector< vector<int> > V;
vector<int> v;
v.push_back(1);V.push_back(v);v.clear();
for(i=1;i<=100;i++)
{
temp = 0;v.clear();
l = V[i-1].size();
for(j=0;j<l;j++)
{
val = V[i-1][j]*i+temp;
v.push_back(val%10);
temp = val/10;
}
if(temp != 0) v.push_back(temp);
V.push_back(v);
}
Lol bigint worked great!!
Lol bigint worked great!! java isnt that bad. Should try it with the arrays though. Is it faster that way
somebody tell me why my code
somebody tell me why my code is not working..
when i'm running on my pc..it is showing correct output..
import java.util.*;
public class Main {
/**
* Creates a new instance of <code>Main</code>.
*/
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
int t=input.nextInt();
int x[]=new int[t];
for(int i=0;i<t;i++)
x[i]=input.nextInt();
for( int i=0;i<t;i++)
{
System.out.printf("%dn",fact(x[i]));
}
}
public static int fact(int n)
{
if(n==0 )
return 1;
else
return n*fact(n-1);
}
}
You obviously haven't tested
You obviously haven't tested your code on any large inputs. Read the constraints again.
i have solved Small Fractions
i have solved Small Fractions problem many times on my machine bt when i have submitted its givin run time error problem wh so??
Infact i did coding on the online compiler as well .
Please help as da prog is workin fine.
pls answer it admin
pls answer it admin
Go to
Go to http://www.codechef.com/wiki/. In particular read the Status Codes section, though you should also read the FAQ.
dis is my code for small
dis is my code for small factorial when i submitted its givin wrong answer why???
It is not working fine on
It is not working fine on your machine. Firstly, it is printing out things that shouldn't appear in the output. You have to print exactly what it tells you to print and nothing else.
Secondly, it isn't even giving the right output for the sample input. In fact it gives the wrong answer for every single input.
And lastly, the input could be up to 100. You obviously haven't tested it on an input of this size.
Hai Smerity, how's life? (:
Hai Smerity, how's life? (:
as a completely unrelated,
as a completely unrelated, there seems to be an interesting trend - people who can't write in a human language can't write in a programming language as well.
This is my pgm its working
This is my pgm its working upto 15 numbers but not working beyond that
so please help me
#include<stdio.h>
int main()
{
unsigned int fact=1;
int t,n,i;
scanf("%d",&t);
while(t!=0)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("n%u",fact);
t--;
fact=1;
}
}
You already found the problem
You already found the problem yourself. Why isn't it working for anything greater? Because an unsigned int cannot hold the result. You need something that will work for much bigger numbers.
don't use this library
don't use this library #include<conio.h>,it is depricated in gcc or g++
#include < stdio.h >#include
#include < stdio.h >
#include < stdlib.h >
main()
{
short int i, j, k, top;
int num;
short int *p, *ans_array;
scanf("%d", &num);
p = calloc(num, sizeof(short));
for(i = 0; i < num; i++){
scanf("%d", &k);
p[i] = k;
}
for( i = 0; i < num; i++){
ans_array = calloc(p[i] * 2, sizeof(short));
ans_array[0] = 1;
top = 0;
for(j = 1; j <= p[i]; j++){
for(k = 0; k <= top; k++)
ans_array[k] *= j;
for(k = 0; k < top; k++){
if(ans_array[k] > 9){
ans_array[k + 1] += ans_array[k] / 10;
ans_array[k] %= 10;
}
}
while(ans_array[k] > 9){
//ans_array[k + 1] = 0;
ans_array[k + 1] += ans_array[k] / 10;
ans_array[k] %= 10;
k++;
}
top = k;
}
for(k = top; k >= 0; k--)
printf("%d", ans_array[k]);
printf("n");
free(ans_array);
}
free(p);
return 0;
}
Please tell me what's wrong with it,it gets a Compilation Error when it runs!
thank you in advance.
It doesn't work on any input
It doesn't work on any input because the first thing you print out is 'enter the number' which is not part of the correct output.
It doesn't work on large inputs at all because of overflow. Haven't you tested your code?
whats wrong with this
whats wrong with this code?
#include<stdio.h>
void factorial(int j)
{
int a[200]={0};
int temp,m=0,temp1,temp2=0;
temp=j;
do
{
a[m]=temp%10;
temp=temp/10;
m++;
}while(temp!=0);
j--;
temp=0;
temp2=--m;
for(;j>1;j--)
{
m=0;
do
{
temp1=(a[m]*j+temp)%10;
temp=(a[m]*j+temp)/10;
a[m]=temp1;
m++;
}while((temp!=0) || (m<=temp2));
temp2=--m;
}
for(;m>=0;m--)
printf("%d",a[m]);
}
int main()
{
int i,j,k=1;
scanf("%d",&i);
for(;i>0;i--)
{
scanf("%d",&j);
if(j==0)
printf("%d",k);
else
factorial(j);
}
return 0;
}
Hi I've submitted my code but
Hi I've submitted my code but keep reciving a runtime error. The code works fine on my computer for all test cases. Can anyone see where it might be failing here?
Thanks
oops sorry, I thought this
oops sorry, I thought this was a pubic code solution here is my code.
[code]
#include <stdio.h>
int main () {
int array[150];
int results[150];
int cases=0,counter=0,counter2=0;
for(counter=0;counter<150;counter++){
results[counter]=1;
}
scanf("%d",&cases);
for(counter=0;counter<cases-1;counter++){
scanf("%dn",&array[counter]);
}
for (counter=0; counter<cases; counter++) {
for(counter2=1;counter2<=array[counter];counter2++){
results[counter]=results[counter]*counter2;
}
}
for(counter=0;counter<cases;counter++){
if(array[counter]==0){
printf("0n");
}
else {
printf("%dn",results[counter]);
}
}
}
[/code]
I have submited the code
I have submited the code which is working fine in my PC but i am gettign wrong answer every time
my problem ID is 154390
pls help
please tell me how to
please tell me how to perticipate in the january algo challenge....
is it possible without forming a team?
if not , how can one form a team????
please admin or aniruddha or stephen.....
answer me..
I m getting result but on my
I m getting result but on my system but each time time limit exceeded.... pls help!!!
@Mazharul: No need to form
@Mazharul: No need to form teams, in fact I don't think it's fair to do so. Once the contest starts, the problems become visible at http://www.codechef.com/JAN10/, and you solve them same as the test problems, on your own.
@jhon thank you buddy..
@jhon thank you buddy..
@admin can u plzz let me knw
@admin
can u plzz let me knw why m i getting wrong answer
i chcked the answer for 100! and it is correct
bt dont knw why is the server is saying it wrng :(
dear admin i hv correctly
dear admin
i hv correctly solved the above problem by reading the tutorial 2 this problem . . .but i want to optimize the sol. by saving two digits in each array element as suggested at the last of tutorial. . .for this i have used x%100 and x/100. . . .instead of x%10 nd x/10. . .bt the problem wid this method is that "the solution differs in number of zeroes". . . i think when a term wid two zero's come it is treated as a single zero after division. . .so please guide me tht How can i retain those zero's in my result array ? ? ? ? ?
plzz reply at least ! ! !
plzz reply at least ! ! !
@Ankush Keep a flag to
@Ankush Keep a flag to specify minimum field width.
@Sumit Check for other numbers.
@Anurag Please read tutorial
This is my code i m getting
This is my code i m getting answer in my system but not here.suggest me
#include <iostream>
using namespace std;
long double fact(long double f);
main()
{
long double b,c[100];
int d;
std::cin>>b;
for(d=0;d<b;d++)
{
cin>>c[d];
}
for(d=0;d<b;d++)
{
c[d]=fact(c[d]);
}
for(d=0;d<b;d++)
{
std::cout<<c[d]<<"n";
}
}
long double fact(long double f)
{
long double g=f;
if(f==0)
return 1;
else
g=g*fact(f-1);
return g;
}
You aren't printing the exact
You aren't printing the exact answer for any input 10 or higher.. you must have only tested your program on something from 1 to 9.
Program runs fine on my
Program runs fine on my computer but when i submit it gives runtime error
O/P on my PC is like:
5
11
39916800
5
33720
10
1610130412800
20
573539285346655414026240000
4
24
Wats wrong Why does it Give Runtime Error
I MODIFIED MY OUTUP NOW BUT
I MODIFIED MY OUTUP NOW BUT STILL IT SHOWS THE SAME RUNTIME ERROR. CAN ANYONE HELP !!!!!
I DID EVERYTHING AS IT WAS MENTIONED IN THE TUTORIAL . .................PLEASE ADMIN !!!!
SHOULD I DISCLOSE THE CODE I HAVE WRITTEN HERE
MY NEW O/P IS:
5
11
5
10
20
4
39916800
33720
1610130412800
573539285346655414026240000
24
sorry got the issue. . . in
sorry got the issue. . . in few cases output was wrong
Please help... I've solved
Please help...
I've solved many problems on this site in C language and tred my solution on both TurboC and MS Visual C++.
Now I've also tried the solution of this problem on gcc.
I'm still getting a run-time error
Your code is missing the
Your code is missing the required return 0.
i submitted the folling
i submitted the folling code,what went wrong....
using System;
class Program
{
static void Main(string[] args)
{
Int64 i = Convert.ToInt64 ( Console.ReadLine ());
Int64[] x = new Int64[i];
Int64 j;
for( j= 0; j<=i-1; j++)
{
x[j] = Convert.ToInt64(Console.ReadLine());
Int64 fact = 1;
for (Int64 k = 1; k <= x[j]; k++)
{
fact = fact * k;
}
x[j] = fact;
}
for (Int64 dis = 0; dis <= i - 1; dis++)
{
Console.WriteLine(x[dis]);
}
}
}
You haven't tested it, have
You haven't tested it, have you? Test it.
ya.... it is giving proper
ya....
it is giving proper o/p:
No it isn't. It is failing on
No it isn't. It is failing on nearly every single case. What test cases did you try?
#include<stdio.h> #include<s
#include<stdio.h>
#include<string.h>
int multiply(int array[],int i,int size)
{
int d=0,c=0;
int l=size;
int j=0;
while(j<l)
{
d=(array[j])*i+c;
array[j]=(d%10);
c=d/10;
j++;
}
if(c>0)
{
array[size++]=c%10;
c=c/10;
}
return size;
}
int dofactorial(int array[],int number,int size)
{
int i=1;
while(i<=number)
{
size=multiply(array,i,size);
i++;
}
for(i=size-1;i>=0;i--)
printf("%d",array[i]);
return size;
}
int main()
{
int n;
scanf("%d",&n);
int array[50];
int number;
while(n>0)
{
array[0]=1;
int size=1;
scanf("%d",&number);
size=dofactorial(array,number,size);
printf("n");
n--;
}
return 0;
}
i am getting correct o/p on my computer,but here its showing run time error !! why??
How big is 100! ?
How big is 100! ?
Hey ! plz help me I wrote
Hey ! plz help me
I wrote the code:
#include<stdio.h>
int main()
{
int arr[200],arrn[100];
int i,j,x,m,t,temp,index;
scanf("%d",&t);
i=0;
while(i<t)
{
scanf("%d",&arrn[i]);
i++;
}
i=0;
while(i<t)
{
m=0;
arr[0]=1;
for(j=2;j<=arrn[i];j++)
{
temp=0;
index=0;
do
{
x=arr[index]*j+temp;
arr[index]=x%10;
temp=x/10;
index++;
}while(index<=m);
while(temp!=0)
{
m++;
arr[m]=temp;
temp=temp/10;
}
}
i++;
while(m>=0)
{
printf("%d",arr[m]);
m--;
}
printf("n");
}
return 0;
}
and it works fine on my pc. bt here wrong answer is generated.
Please read the FAQ before
Please read the FAQ before posting comments.
You have one small bug that is causing you to get the wrong answer for the majority of inputs. Try testing your output in more detail.
i appologise ,, and thanx
i appologise ,,
and thanx
it is a nice problem.
it is a nice problem.
Hello Admin May i know what
Hello Admin
May i know what was the problem in my latest solution( ID 174789 )
Thanks in advance
ever time my code get RTE
ever time my code get RTE :::::
plz give me some INput && output
#include<stdio.h>
#include<string.h>
char a[10005][30005]; //digit require
char fac[30005]; //digit require
int main()
{
long hand,i,j,g,len,k,test;
fac[0]='1';
strcpy(a[0],fac);
len=1;
for(i=1;i<=1000;i++) //upper limit== digit require
{
hand=0;
for(j=0;j<len;j++)
{
hand=(fac[j]-48)*i+hand;
fac[j]=hand%10+48;
hand=hand/10;
}
while(hand!=0)
{
fac[len]=hand%10+48;
hand=hand/10;
len++;
}
fac[len]=0; // ' ' ASCI VALUE==0
strcpy(a[i],fac);
}
scanf("%ld",&test);
while(test--)
{
scanf("%ld",&k);
len=strlen(a[k]);
for(g=len-1;g>=0;g--)
printf("%c",a[k][g]);
printf("n");
}
return 0;
}
Please read the FAQ.
Please read the FAQ.
Hello below is my code for
Hello
below is my code for which i m getting RTE but i have tested it for all 100 numbers it i sworking fine
Kindly let me know where is the mistake
import java.text.DecimalFormat;
class Main{
public Main() {
super();
}
public static void main(String[] args)
{
DecimalFormat formatter = new DecimalFormat("#0");
Double[] input = null;
int inputReceived = 0;
inputReceived = Integer.valueOf(args[0]);
input = new Double[inputReceived];
for(int i=0; i<inputReceived; i++){
int j = i;
j++;
input[i] = Double.valueOf(args[j]);
}
for(int k=0; k<inputReceived; k++ ){
double fact= 1;
for (int l= 1; l<=input[k]; l++){
fact=fact*l;
}
System.out.println(formatter.format(fact));
}
System.gc();
}
}
Thanks in advance
Regards
Vivek
You aren't provided input
You aren't provided input from the command line arguments. Read the FAQ.
i am getting correct value
i am getting correct value but still it is not accepting.
If it is not accepting then
If it is not accepting then you are not getting the correct value.
im getting runtime erroer and
im getting runtime erroer and one more thing when i try to change int datatype to double funtion it shows funtion should return a value
int datatype not showing factorial above 15
heres my code ...
#include<stdio.h>
//#include<conio.h>
int fact(int);
int main()
{
int no,f,t,i;
//clrscr();
//printf("enter the number of test cases below 15n");
scanf("%d",&t);
if(t>15)
{
return (main());
}
else
{
for(i=1;i<=t;i++)
{
// printf("nEnter Number n" );
scanf("%d",&no);
f=fact(no);
printf("%dn",f);
}
}
// getch();
}
int fact (no)
{
int f;
if(no<=1)
return 1;
f=no*fact(no-1);
return(f);
}
Please tell your code before
Please tell your code before asking for help. The problems with your code will be obvious once you test it.
Stephen Merriman - 16th
How big is 100! ?
my program giving me following ans for 100!
933262154439441526816992388562667004907159682643816214685929638952175999932299156894146397615651828625369792827223758251185210916864000000000000000000000000
M I right if not please reply
Stephen Merriman - 16th
How big is 100! ?
my program giving me following ans for 100!
933262154439441526816992388562667004907159682643816214685929638952175999932299156894146397615651828625369792827223758251185210916864000000000000000000000000
M I right if not please reply
it seems that ans is
it seems that ans is completely visible
its actually
100! =
933262154439441526816992388562667004907159682643816214685929638952175999932299156894146397
615651828625369792827223758251185210916864000000000000000000000000
Nearly. But not quite. You're
Nearly. But not quite. You're missing 2 digits somewhere in the middle.
#include<stdio.h>int fact(int
#include<stdio.h>
int fact(int num) {
int fac, j;
fac = 1;
for(j = 1; j <= num; j++) {
fac = fac * j;
}
return fac;
}
int main() {
int x, i, input, res, y[100];
scanf("%d", &x);
if(1<=x<=100) {
for(i = 0; i < x; i++) {
scanf("%d", &input);
if(1<=input<=100) {
y[i] = input;
}
}
}
for(i = 0; i < x; i++) {
res = fact(y[i]);
printf("%dn", res);
}
return 0;
}
why this code showing wrong answer?
Please don't post code. Read
Please don't post code. Read the FAQ; it is giving wrong answer for a reason that would be very obvious if you had tested it properly.
can you please check what is
can you please check what is error in my code
check under my submissions
please post solution
its workin gfine in my dev c++
The problem says 1 <= n <=
The problem says 1 <= n <= 100.
Except you clearly haven't tried anything near 100. (And you are printing out the input again too, which you aren't meant to do).
i am receiving runtime
i am receiving runtime error...
plz help me ...
import
import java.io.DataInputStream;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
DataInputStream d = new DataInputStream(System.in);
int i,k = 0;
int j[];
long fact;
try{
i = Integer.parseInt(d.readLine());
j = new int[i];
while (i > 0){
j[k] = Integer.parseInt(d.readLine());
k++;
i--;
}
k--;
for (k=0;k<j.length;k++){
fact = j[k];
i = (int) fact;
while(i>1){
fact = fact*(i-1);
i-- ;
}
System.out.println(fact);
}
}
catch(Exception e){
e.printStackTrace();
}
}
}
// I am not sure what is wrong with this code, works perfectly fine on my system.
//someone help
No it doesn't. It very
No it doesn't. It very clearly fails on any large input.
I tried with t = 60, it was
I tried with t = 60, it was not giving me any runtime error.
For an input of 60 you print
For an input of 60 you print -8718968878589280256.. I'm not sure why you think 60! is going to be a negative number.
@ to all who say "I have
@ to all who say "I have checked for 100! and I got right answer!" wondering how you checked :P
My Java code for this
My Java code for this program is
import java.util.*;
import java.math.*;
class fctrl2
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int k = in.nextInt();
for(int i=0;i<k;i++)
{
int n = in.nextInt();
BigInteger fact = BigInteger.valueOf(1);
for(int j=0;j<n;j++)
{
fact = fact.multiply(BigInteger.valueOf(n-j));
}
System.out.println(fact);
}
}
}
on submitting the solution, it is giving compile time error and the warning is
/sources/Main.java:4: class fctrl2 is public, should be declared in a file named fctrl2.java public class fctrl2 ^ 1 error
Can anyone explain what is this
Also my code is working fine
Also my code is working fine for 100!
FAQ
FAQ
codechef is not accepting a
codechef is not accepting a php solution please check
i have followed all the guidelines
but its not accepting php code following is code it says wrong answer please help to sort out
thanks
<?php
$number=fgets(STDIN, 8);
for($i=0;$i<$number;$i++)
{
$in=fgets(STDIN, 8);
$fact[$i]=1;
for($j=1;$j<=$in;$j++)
$fact[$i]=$fact[$i]*$j;
}
for($i=0;$i<$number;$i++)
{
echo $fact[$i];
echo "n";
}
?>
what should be output in case
what should be output in case of value higher than 100?
The problem statement clearly
The problem statement clearly states the value will be at most 100.
#include<iostream.h>#include<
#include<iostream.h>
#include<conio.h>
void main()
{
int fact=1;
int i;
clrscr();
cout<<"enter any number"<<endl;
cin>>i;
while(i!=0)
{
fact=fact*i;
i--;
}
cout<<"factorial of given number="<<fact;
getch();
}
Hi, I got a RTE for my
Hi,
I got a RTE for my submission. I dont think I can paste the code here. Can someone check the code and hint me where I am using up too much memory. I have used an array of 200 as per the tutorial. Cant figure out any other place which could cause memory problems.
Thanks,
Umang
for this
for this input:
8
1
2
5
50
3
100
4
17
I write this output:
1
2
120
30414093201713378043612608166064768844377641568960512000000000000
6
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
24
355687428096000
and I cannot see why I'm getting 'wrong answer' - these values and others I've tried seem right, the output format seems right but clearly I'm missing something, can anyone help?
oops, something seems to have
oops, something seems to have eaten the end of the 100! result, 64000000000000000000000000 is missing
can u help me in telling how
can u help me in telling how to improve my efficiency as my code is correct but still it is not upto the mark as other's have submitted and their execution time is less and memory is also less .
How to handle large numbers
How to handle large numbers which are out of capacity of "long" datatype in "C"....??
The same way you would handle
The same way you would handle them on paper.
Rite....we may handle a
Rite....we may handle a number containing 1000 digits, on paper, but no datatype in C can make that. We can handle an integer of any length by long datatype in python. I want to know if we make the same there in C by using any data structures.
@Harsh use char array for big
@Harsh
use char array for big integer in C
in the folllowing python
in the folllowing python code
t = input()
p=1
if(int(t)>=1):
if(int(t)<=100):
for i in range(int(t)):
n = input()
if(int(n)>=1):
if(int(n)<=100):
j = int(n)
if(j>=1):
p*=j
j-=1
print(p)
please suggest the indentation wise position of last print statement, highlighted in bold.
does java takes more time
does java takes more time than c and c++??
i have done the problem... but time limit exceeded...
none of the successful subbmissions were in java...
heres the code..
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Life {
public static void main(String[] args) throws NumberFormatException, IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
while(n-->0){
int k=Integer.parseInt(br.readLine());
String res="1";
for(int i=2;i<=k;i++){
res=multip(res,""+i);
while(res.startsWith("0")){
res=res.substring(1);
}
}
System.out.println(res);
}
}
private static String multip(String s1, String s2) {
String[] re=new String[s1.length()];
for(int i=s1.length()-1;i>-1;i--){
int rem=0;
re[i]="";
for(int j=i+1;j<s1.length();j++)
re[i]="0"+re[i];
for(int j=s2.length()-1;j>-1;j--){
int a=Integer.parseInt(""+s1.charAt(i));
int b=Integer.parseInt(""+s2.charAt(j));
re[i]=((a*b+rem)%10)+re[i];
rem=(a*b+rem)/10;
}
re[i]=rem+re[i];
for(int j=0;j<i;j++)
re[i]="0"+re[i];
}
String res="";
int rem=0;
for(int j=re[0].length()-1;j>-1;j--){
for(int i=0;i<re.length;i++){
rem+=Integer.parseInt(""+re[i].charAt(j));
}
res=(rem%10)+res;
rem/=10;
}
return res;
}
}
You will find Haskell
You will find Haskell solution to this problem @ http://www.janeve.me/articles/learning-haskell/small-factorials-solution-in-haskell with a brief explanation of how the code works.
#include<stdio.h>#include<con
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int i,j=1,t,temp,x,n,m[100],n1[100][150]={0},qq,ii;
scanf("%d",&t);
for(qq=0;qq<t;qq++)
{
scanf("%d",&n);
n1[qq][0]=1;
for(i=2;i<=n;i++)
{
m[qq]=0,temp=1;
while(1)
{
if(m[qq]==0)
temp=0;
if(m[qq]>=j)
{
if(temp==0)
break;
n1[qq][m[qq]++]=(temp%10);
temp/=10;++j;
}
if(m[qq]<j)
{
x=n1[qq][m[qq]]*i+temp;
n1[qq][m[qq]]=x%10;temp=x/10;
m[qq]++;
}
}
}
}
for(qq=0;qq<t;qq++)
{
for(ii=m[qq]-1;ii>=0;ii--)
printf("%d",n1[qq][ii]);
printf("n");
}
//tch();
return 0;
}
pls help me
hear i did not find any
hear i did not find any runtime errors but after submition it shows a runtiome error.
how know it?
Have a look at the FAQ (in
Have a look at the FAQ (in particular, the first section and the section called 'Why do I get an NZEC?').
The following program is
The following program is working perfect and got ac , I wanna know how fact variable is able to store 100!
t=input()
l=[]
def fac(n):
fact=1
for i in xrange(1,n+1):
fact=fact*i
return fact
for i in xrange(1,t+1):
j=input()
l.append(fac(j))
print('n')
for i in l:
print i
err , there are no spaces in
err , there are no spaces in program ...... view the program here. http://pastebin.com/PN8ZR1EN
can anybody tell me what's
can anybody tell me what's wrong with this? I'm getting the right output in my gcc compiler!
thanx...
#include<stdio.h>
int main(){
int i,j,k;
unsigned int a[200],num,m,mul,temp=0,x,inputs;
scanf("%d",&inputs);/*number of test cases.*/
for(i=0;i<inputs;i++){
scanf("%d",&num);
temp=num;
m=0;
while(temp>0){
a[m]=temp%10;
temp/=10;
m++;
}
temp=0;
for(j=num;j>0;j--){
mul=j-1;
for(k=0;k<m;k++){
x=a[k]*mul+temp;
a[k]=x%10;
temp=x/10;
}
while(temp>0){
a[m]=temp%10;
m++;
temp/=10;
}
}
for(j=m;j>=0;j--){
printf("%d",a[j]);
}
}
return 0;
}
fact = input()result = 1for i
fact = input()
result = 1
for i in range(1, fact+1):
result *= i
print result
What wrong in above python solution. On my machine, it even returns the correct solution for 100.
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
Read the input format, and
Read the input format, and make sure your program works on the sample input.
#include<iostream.h> #includ
#include<iostream.h>
#include<conio.h>
void main()
{
int n,x,z=1;
clrscr();
do
{
cout<<"Enter any no:";
cin>>n;
if(n<0 || n>100)
{
cout<<"Enter between the number 0 to 100 only.";
}
for(x=1;x<=n;x++)
{
z=x*z;
}
cout<<"nThe factorial of "<<n<<" number is:"<<z;
}while(n<0 && n>100);
getch();
}
@kavibharathi Read the input
@kavibharathi
Read the input constraints.
//#include<conio.h> #include
//#include<conio.h>
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int test,i,j,k,l,m,n,arr[160],temp,fact;
scanf("%d",&test);
while(test--)
{
scanf("%d",&n);
arr[0]=n;
for(i=1;;i++)
{
if(arr[0]!=0)
{
arr[i]=arr[0]%10;
arr[0]=arr[0]/10;
}
else
break;
}
for(j=n-1;j>1;j--)
{
temp=0;
for(k=1;k<i;k++)
{
m=arr[k];
arr[k]=(m*j+temp)%10;
temp=(m*j+temp)/10;
}
for(l=i;;l++)
{
if(temp!=0)
{
arr[l]=temp%10;
temp=temp/10;
}
else
break;
}
i=l;
}
for(j=i-1;j>0;j--)
printf("%d",arr[j]);
}
//getch();
return 0;
}
Buddy ! where are the
Buddy ! where are the newlines ?
My php code is below. It says
My php code is below. It says time limit exceeded. I have tested it. It works fine even with larger values. Still it says time limit exceeded. Can someone point me what i am doing wrong ?
<?php
$file = fopen($argv[1], "r");
$num_of_lines_in_file = 0;
while(!feof($file))
{
$records = fgets($file);
//$records = trim($lines);
if($num_of_lines_in_file == 0)
{
$totalrecords = $records;
}
else
{
echo nfact($records);
echo "n";
}
$num_of_lines_in_file++;
}
fclose($file);
function nfact($n)
{
if ($n == 0)
{
return 1;
}
else
{
return $n * nfact($n - 1);
}
}
?>
You need to read input from
You need to read input from stdin. See the FAQ.
this is the only problem i
this is the only problem i was able to solve here. It judges you how u r able to manage the time space tradeoff.
1)create a class defining big numbers as explained in the tutorial and overload the multiplication operation in ur class.
2)Create an object array of 101 elements (0 to 100).
Suppose user enters 44 as input. starting frm 0 fill the array corresponding to the index as u calculate the factorial, so that next time if user enters value less than 44, its factorial could be easily obtained frm the array by indexing it , because to find 44! we have already stored the intermediate calculations. if user happens to enter value more than 44 say 70 later, then continue the halted loop from 44 to 90, and save the factorials falling within this range too as u proceed.
thus the loop would run only once and data can be accessed any number of times. This was the time space tradeoff.
O god,, help me with other
O god,, help me with other probs...
Its very difficult to to get the striking thought.
Can anyone plzz help me gaining skills??
plzz....
in my case the problem is
in my case the problem is caused by 100!
In Java the variable long is not large enough to store the answer. So we have to use java.math.BigInteger
http://www.codechef.com/wiki/faq#How_can_I_store_very_very_large_integers_accurately
maybe this link can help you
http://leepoint.net/notes-java/data/numbers/10biginteger.html
I ve submitted my code in
I ve submitted my code in java using BigDecimal class
and it is working fine on my machine
bt i m getting compilation error while submitting here.
Can anyone help me in this case.
I have the strong feeling
I have the strong feeling that the "wrong answers" being shown against my submissions for this and other problems are due to an over-strict infexible output format demanded, e.g. whether the newline is before the data or after the data. People lose enthusiasm if such trivialities are held so sacrosanct.
Your strong feeling is
Your strong feeling is incorrect. Any extra whitespace in your output is ignored; you could print 20 tabs between each answer and no newlines if you preferred and still be judged correct. However, if an input file was, say
3111and your output was 111, then that would clearly be a wrong answer.
I ve submitted my code in
I ve submitted my code in java using BigDecimal class
and it is working fine on my machine
bt i m getting compilation error while submitting here.
Can anyone help me in this case.
Admin plzz reply.....
I honestly have no idea.
I honestly have no idea. Resubmitting exactly the same code that you got compile error for was accepted for me. Must have been some sort of glitch in the system.
What is wrong in this
What is wrong in this code
#include <stdio.h>
#define MAX 1000
void fact(int k)
{
register int i ; // register variable for fast access
int n[MAX],rem=0,total,count;
for(i=0;i<MAX;i++)
n[i]=0;
n[MAX-1]=1;
if ( k < 2 )
printf("1");
else
{
for(count=2;count<=k;count++)
{ i=MAX-1;
while(i>0)
{ total=n[i]*count+rem;
rem=0;
if(total>9)
{ n[i]=total%10;
rem=total/10;
}
else
n[i]=total;
i--;
}
rem=0;
total=0;
}
while(n[i]==0)
i++;
for(;i<MAX;i++) //print of final arry.
printf("%d",n[i]);
}
}
int main()
{
int n,i,item;
int input[100];
scanf("%d ", &n);
for (i=0 ; i < n ; i++ )
{
scanf("%d/n",&input[i] );
}
for( i=0 ; i< n ; i++ )
{
fact(input[i]);
printf("n");
}
return 0;
}
#include <stdio.h> long long
#include <stdio.h> long long int fact(int n) { if(n==0) return 1; return n*fact(n-1); } int main() { int t,a; scanf("%d",&t); while(t>0) { scanf("%d",&a); printf("%lldn",fact(a)); t--; } return 0; }It gives the wrong answer for
It gives the wrong answer for nearly every input. Have you not tried any large ones at all?
WTH
WTH
can anybody tell why it is
can anybody tell why it is giving wrong answer.........please
#include<stdio.h>
int fact(int n)
{
int f=1;
while(n)
{
f=f*n;
n--;
}
return f;
}
int main()
{
int t,n,i;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
printf("%dn",fact(n));
}
return 0;
}
See my comment two above
See my comment two above yours.
can any1 plz tel me how can i
can any1 plz tel me how can i get the real solution of tthis question
can any1 tel me how can i get
can any1 tel me how can i get the solution of the prob??????
?
can any one check the
can any one check the following...
http://www.codechef.com/viewsolution/385399
i didnt understand why its wrong.....
Have you tried checking your
Have you tried checking your solution for 100? It won't be anything like what you print, since doubles aren't accurate enough to store that many digits. (In fact, it starts giving wrong answers even for much smaller inputs).
@Merriman: I checked my
@Merriman: I checked my values. But i am displaying my results for larger values in exponential format which are same as that of values produced in MScalculator. Is this an error?
Yes. You must produce every
Yes. You must produce every single digit.
#include<iostream> using
#include<iostream>
using namespace std;
class BigInt
{
private:
int m;
int a[100];
void parstoarr(int inp)
{
int i=0;
while(inp!=0)
{
int r=inp%10;
inp=inp/10;
a[i++]=r;
m++;
}
m--;
}
public:
BigInt()
{
m=1;
a[0]=1;
}
void multp(int p)
{
int x,temp=0;
int i=0;
for(;i<m;i++)
{
x=(a[i]*p)+temp;
a[i]=x%10;
temp=x/10;
}
if(temp>0)
{
while(temp!=0)
{
a[i++]=(temp%10);
temp=temp/10;
m++;
}
}
}
void shownum()
{
for(int i=m-1;i>=0;i--)
{
cout<<a[i];
}
cout<<endl;
}
void fctrl(int c)
{
for(int j=1;j<=c;j++)
{
this->multp(j);
}
}
};
int main()
{
int b[100];
int a;
cin>>a;
for(int j=0;j<a;j++)
{
cin>>b[j];
}
for(int j=0;j<a;j++)
{
BigInt i;
i.fctrl(b[j]);
i.shownum();
}
return 0;
}
Please help, its telling that the result is wrong although as per the test cases I used its correct.
var t:integer;
i run it in 0.00 sec Lang: PAS =)
Whats wrong with my
Whats wrong with my code???
It is finely working in my machine...
#include<stdio.h>
#include<stdlib.h>
main()
{
int count, *num, f,i ;
printf("nEnter no. of numbers:t");
scanf("%d",&count);
num = ( int *)malloc( count*sizeof(int ));
for( i=0; i<count; i++ )
{
scanf("%d",(num+i));
}
for(i=0;i<count;i++)
{
printf("%dn", fact( *(num+i) )) ;
}
}
int fact( int num )
{
int i,result=1;
for( i=1; i<= num; i++ )
result = result*i ;
return( result );
}
Hi can anyone check this
Hi can anyone check this solution http://www.codechef.com/submit/complete/46523-24--4d08d0bb8ac15 it is giving wrong answer again and again. I have checked my solution for all no.s 1-100 and all of them are correct. My code if giving the exact output as other accepted solution output for numerous test cases. Please help me on this
Your last two submissions are
Your last two submissions are clearly wrong since they don't even work on the sample input. As for some of the submissions I checked before that; you said you tested 1-100, but have you tested 100-1?
To Admin: Please give some
To Admin: Please give some bigger test cases as I am not able to figure out whether the result I am getting is right or wrong!
My solution is evaluated as "Wrong Answer". If possible please check the issue.
http://www.codechef.com/viewsolution/401284
If you're using windows you
If you're using windows you could always use windows calculator (similar options for linux)..
Got the issue! Logical
@ Stephen Merriman Hi
@ Stephen Merriman
Hi Stephen, Please help into this.
I solved problems with all inputs and i got answer too.
Below is my file. Please have a look. I am getting 'wrong answer' error.
I checked all extra character but all program is correct....
http://www.codechef.com/viewsolution/406227
hey plz somebody help me here
hey plz somebody help me
here it is my code
#include<stdio.h>
int a[200],count=0,c=0;
void make_arr(int n)
{
int b=0,i=0;
do
{
b=n%10;
a[i]=b;
i++;
n=n/10;
count++;
}while((n/10)!=n);
}
void counti(int m)
{
do
{
m=m/10;
c++;
}while((m/10)!=m);
}
void countfact(int m)
{
int x;
static int j,temp;
x=m*a[j]+temp;
a[j]=x%10;
temp=x/10;
j++;
}
int main()
{
int n,i,b,j,m=0,l=0;
printf("enter no ");
scanf("%d",&n);
make_arr(n);
m=n;
for(i=n;i>0;i--)
{
m--;
counti(m);
l=count+c;
for(j=l;j>0;j--)
{
countfact(m);
}
}
/* for(j=0;j<9;j++)
{
printf("%d",a[j]);
} */
return 0;
}
can anyone tell me why my loop is not running second tym???
it gives the result only
admin plz help me
admin plz help me
PLZZZZZZZZZZZ HELP ME.....Iam
PLZZZZZZZZZZZ HELP ME.....Iam geting Run time error....
This is my code.........................
#include<stdio.h>
#include<string.h>
int main()
{
short int i,j=0;
unsigned short int k=0,l=0,len1=0,len2=0,y=0,carry=0,x=0;
short int t[100],m=0,n=0,input=0;
char res[2][210]={"1","2"};
char one[210],two[4];
scanf("%d",&n);
if(n>100) exit(1);
for(i=0;i<n;i++)
{
scanf("%d",&t[i]);
if(t[i]>100) exit(1);
}
for(m=0;m<n;m++)
{
input=t[m];
one[2]=(char)(((input%10)+48));
input/=10;
one[1]=(char)(((input%10)+48));
input/=10;
one[0]=(char)(((input%10)+48));
one[3]=' ';
input=t[m];
if(input>2)
{
while(input!=1)
{
two[1]=(char)(((input-1)%10)+48);
two[0]=(char)(((input-1)/10)+48);
two[2]=' ';
len1=0;
len1=strlen(one);
for(i=1,k=0,l=0;i>=0;i--)
{
carry=0;
for(j=len1-1;j>=0;j--)
{
x=(one[j]-48)*(two[i]-48)+carry;
y=x%10;
carry=x/10;
res[k][l++]=(char)(y+48);
}
res[k][l]=' ';
l=0;
res[++k][l++]='0';
}
len1=0;
len2=0;
len1=strlen(res[0]);
len2=strlen(res[1]);
for(i=0;i<(len2-len1);i++)
{
res[0][len1++]='0';
}
res[0][len1]=' ';
carry=0;
for(i=0,k=0;i<len1;i++)
{
x=(res[0][i]-48)+(res[1][i]-48)+carry;
res[1][k++]=(char)((x%10)+48);
carry=x/10;
}
res[1][k++]=(char)(carry+48);
res[1][k]=' ';
len1=0;
len1=strlen(res[1]);
for(i=0;i<len1;i++)
{
one[i]=res[1][(len1-1)-i];
}
one[i]=' ';
input--;
}
i=0;
j=0;
k=0;
while(one[i]!=' ')
{
if(one[i]=='0'&&k==0)
{
i++;
continue;
}
else
k=1;
res[0][j++]=one[i++];
}
res[0][j]=' ';
printf("%sn",res[0]);
}
else
{
printf("%sn",res[input-1]);
}
}
return 0;
}
hello ppl plz help me out!!!!
hello ppl plz help me out!!!! Above is my code....
#include<stdio.h> long double
#include<stdio.h>
long double func(long double);
void main()
{
long double p;
long double a[200],t,x;
int i,j=0;
scanf("%Lf",&p);
for(i=0;i<p;i++)
{
scanf("%Lf",&t);
x=func(t);
a[j]=x;
j++;
}
printf("n");
for(i=0;i<p;i++)
printf("%Lfn",a[i]);
}
long double func(long double n)
{if(n==0)
return 1;
return (n*func(n-1));
}
See the FAQ.
See the FAQ.
Hey I have used C++.There is
Hey I have used C++.There is no limit(maximum) to find the factorial of a number.I am getting correct answers on my PC but i am getting wrong answer every time on your machine.Can you please tell me what is wrong or any input whose my program gives wrong answer ?Here is my code..
#include<iostream>
#include<stdio.h>
#include<list>
using namespace std;
int main()
{
int tests = 1;
scanf("%d",&tests);
while(tests--)
{
int num = 1;
scanf("%d",&num);
if(num == 2)
{
printf("2");
continue;
}
else if(num <= 1)
{
printf("1");
continue;
}
int temp = num<<1;
list<int> vt;
while( temp > 0)
{
vt.push_front(temp%10);
temp /= 10;
}
int multiplier = 2;
while(++multiplier < num)
{
list<int>::iterator it = vt.end();
int carry_out = 0;
do
{
--it;
int temp1 = (*it) * multiplier; // First multiply
temp1 += carry_out; // Then add carry out
carry_out = temp1/10; // Next carry out is divide by 10
*it = temp1 % 10 ; // This digit changes to ones place of the multiplication
}while(it != vt.begin());
while(carry_out > 0)
{
vt.push_front(carry_out % 10);
carry_out /= 10;
}
}
list<int>::iterator it = vt.begin();
while(it != vt.end())
{
cout<<*it;
++it;
}
cout<<endl;
}
return 0;
}
#include<stdio.h>void main(){
#include<stdio.h>
void main()
{
int i,f,a[10],n,j;
puts("Enter the no of terms");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
f=1;
for(j=1;j<=a[i];j++)
f*=j;
printf("%dn",f);
}
}
hey... if mine input
hey... if mine input is:
5
1
3
123
4
5
then what should be the output and shoud it accept no. after 123.....
plz tel me.....
The problem tells you all
The problem tells you all numbers in the input will be at most 100..
I used "double" for
I used "double" for calculation of factorials and the 100! was also calculated. and the output I printed with the help of System.out.printf("%.0f",factorial) the output was correct but everytime i get Wrong Answer can anyone tell me why?
Are you sure? This is not
Are you sure?
This is not correct.. http://ideone.com/Ridzr
@Neha if you are using the
@Neha
if you are using the method given in the above tutorial then you need not to use
double..since range of ans for 100! ll be larger than that can be hold in double data type
and answer will always be integer
please check my program i am
please check my program i am getting runtime error
can u plz check my program nd
can u plz check my program nd temme wher i went wrong...i got runtym error..:(
nd wil i b able to submit solution one more tym..??
can u plz check my program n
can u plz check my program n tell me what is wrong with this code???
#include<stdio.h> #include<co
#include<stdio.h>
#include<conio.h>
int fact(int num)
{ int k=1,i;
if(num==1)
return(1);
else
{
for( i=1;i<=num;i++)
k=k*i;
}
return(k);}
void main()
{ int n,a[100],i,j;
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&j);
a[i]=fact(j);
}
for(i=1;i<=n;i++)
{
printf("%d",a[i]);
}
getch();
}
what to do with this????
what to do with this????
using namespace std;#include
using namespace std;
#include <iostream>
int main()
{
int t,i,j;
cin>>t;
long double k[t+1],a[t+1];
for (i=0;i<t;i++)
cin>>k[i];
for (i=0;i<t;i++)
a[i]=1.0;
for (i=0;i<t;i++)
{ if (k[i]==0)
a[i]==1;
else
for ( j=1;j<=k[i];j++)
{
a[i]=a[i]*j;
}
}
for (i=0;i<t;i++)
cout<<"n"<<a[i];
return 0;
}
I don't know why is this submission not getting accepted ... infact it's being called wrong ... can you please give me a testcase
what is runtime error...?? i
I have submitted my code 3
I've submitted my code 10
seems scanf is leading to
@flexicoder: You are
can i use recursion
What's wrong with this
@gsatcoet, are you sure your
What is wrong with
@gundeep: Try submitting in
@imnewcoder It worked,
What is the difference
where did i go wrong
you should read the I/O
my code is working on dev
I am getting Run time error.
hello i used "long fact " to
why there is a run time
I created a input text file
my code : #include int
oops found the prob
import java.io.*; class
import java.io.*; class
why the codes i submit here
plz sme1 reply....!
why it is not
@ admin sir kindly help
@swastika21: Do not post the
i get NZEC. I am using
My code : import
i don't know why it is giving
please help
on my pc it is working fine
The common problem is that
I can't understand where the
which type of integer integer
@rokon1cuet_51: Read the
What's wrong with
Hi Admin, Can we have some
#include int main() { int
The only error I get is an
Ok.. I got it :D
Got it. Thank you.
:= not a easy problem ,thanks
what's wrong with this code
i can not understand why my
this program is running
my code is giving a run time
my code is giving wrong
#include #include #include lo
my code #include int
@dageramit your code is