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

×

Small integer factorial

#include<iostream>

using namespace std; int fact(int x) { int f=1; for(int i=1;i<=x;i++) { f=f*i; } return f; }

int main() { int t,n,i,facto; cin>>t; for(i=0;i<t;i++) {="" cin="">>n; facto=fact(n); cout<<facto<<"\n"; } return 0; } now what is wrong??

asked 16 Sep '17, 07:29

mahimagoyen's gravatar image

0★mahimagoyen
1
accept rate: 0%


Here you had unwanted equal signs and one more thing use long instead of int because the number can be large but I don't think so that even long long can hold the factorial of 100, you might need different approach

include<iostream>

using namespace std;

int fact(int x)

{

int f=1;

for(int i=1;i<=x;i++)

{

f=f*i;

}

return f;

}

int main()

{ int t,n,i,facto;

cin>>t;

for(i=0;i<t;i++) {="" cin="">>n;

facto=fact(n);

cout<<facto<<"\n";

}

return 0;

}

link

answered 16 Sep '17, 07:40

kunnu120's gravatar image

2★kunnu120
5189
accept rate: 5%

edited 16 Sep '17, 07:53

toggle preview
Preview

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:

×151
×5
×4

question asked: 16 Sep '17, 07:29

question was seen: 175 times

last updated: 16 Sep '17, 07:53