473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

factorial program

7
can you please answer this:thanks!!!

write a factorial function that returns a factorial of a long int number. Enter the number at the main funtion and call factorial() to carry on calculations and return the result.
Mar 6 '07 #1
10 6277
chella
51
can you please answer this:thanks!!!

write a factorial function that returns a factorial of a long int number. Enter the number at the main funtion and call factorial() to carry on calculations and return the result.

Hi,
U try writing the code and let us know if u have any problem with it.

Regards,
Chella
Mar 6 '07 #2
yusuke
7
sorry,, i really dont know... im still a new student of programming and this program is for advance study. can u help me w/ this?
thanks!
Mar 6 '07 #3
Banfa
9,065 Expert Mod 8TB
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

Administrator

Do you know how to calculate a factorial on paper? Say 5!.
Mar 6 '07 #4
Mack
11
Try using Recursion else simple for loop will work for you , I understand you are beginner same was with me , although i respect all alongwith you.
something like this will go .
see
for (i=0; i<num;i++)
i=i*(i-1)

retun(i)

see this is not way its going to work its just clue to you , so u get enthu to work further on it.

Regards,
Mack.
Mar 6 '07 #5
Here's a tip:

Think recursion, it makes your function about 5 lines...

Not so hard...

Go have a look in the forum, There is a complete Factorial recursion function here...
;-)
Mar 7 '07 #6
yusuke
7
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

Administrator

Do you know how to calculate a factorial on paper? Say 5!.
yes i can... the factorial of 5 is 120...thanks!!!
Mar 10 '07 #7
can you please answer this:thanks!!!

write a factorial function that returns a factorial of a long int number. Enter the number at the main funtion and call factorial() to carry on calculations and return the result.
<code snipped in accordance with the posting guide lines>

<edit=Banfa>
Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.</edit>
Mar 10 '07 #8
Banfa
9,065 Expert Mod 8TB
yes i can... the factorial of 5 is 120...thanks!!!
So you know the mathematical method to get the result of a factorial.

The next step is to write that method down as a series of simple instructions (in any language you like)

And finally you convert those instructions into C
Mar 10 '07 #9
yusuke
7
So you know the mathematical method to get the result of a factorial.

The next step is to write that method down as a series of simple instructions (in any language you like)

And finally you convert those instructions into C
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. int c(int a);
  3. main()
  4. {
  5.     int a;
  6.     printf("Enter a number:");
  7.     scanf("%d",&a);
  8.  
  9.     printf("The factorial number is: ");
  10.     printf("%d",c(a));
  11.     return 0;
  12. }
  13. int c(int a)
  14. {
  15.     int b,z;
  16.     b=1;
  17.     for(z=1;z<=a;z++){
  18.     b=b*z;
  19.     }
  20.     return b;
  21. }
i think i got it right this time...thank u guyzzzzzzzz!!!!!!
Mar 12 '07 #10
Banfa
9,065 Expert Mod 8TB
Looks like it will work, however

1. c is not a good name for a function

2. There is a limit to the input number after which overflow of the integer will cause the answer to be wrong. You may want to consider finding the limit and putting in a check to reject numbers that are too big to calculate.
Mar 12 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Martin Jørgensen | last post by:
Hi, Consider (factorial.cpp): #include <iostream> using namespace std; double R=3.2; /* not used, but R is static because it is a global variable (file scope) */
35
by: aNt17017 | last post by:
This is my code: long fact(int n) { if (n == 0) return(1); if(n > 100) { printf("\t\tERROR: %d is too large for factorial.\n", n); return 1;
8
by: salman | last post by:
this program is giving compile time error. so plse ge me the logic of factorial # include <iostream.h> # include <math.h> void main() { int f,sum=0,i,j,n; cout<<"\nEnter Number: ";
1
by: Tin | last post by:
Dear Sir/Madam, I have one assignment , which need me to write a program to calculate the factorial of an integer, then press the button that would display the result in a label.3 & the...
59
by: Umesh | last post by:
i wrote the following program to calculate factorial: #include<stdio.h> #include<iostream.h> void main() { int i,n; long int p=1; // or long double p=1; for exponential result which I don't...
3
by: Sugandh Jain | last post by:
Hi. How to write a function that will return me the factorial (say in a string) for the any positive integer it takes? When we find a factorial of even say 2000 or a higher number, it will be...
12
by: dynamo | last post by:
Hello everyone,i am a beginner in c++ and i am trying to write a program that outputs the factorial of a number in my own way,however i don't know why it's not working.Thanks for any help.This is the...
1
by: doctor309 | last post by:
hello friends iam not able to get logic behind solving the question mentioned below,,,,i tried a lot using various books.....online tutorials but at the end just lost it...... you ppl are kindly...
2
by: becky808 | last post by:
Hi, I'm trying to write a program to calculate n factorial but it won't compile. Can anyone tell me what I'm doing wrong? #include <iostream> #include <cmath> using namespace std; int...
3
by: Blue sky | last post by:
Hi,I am a new C++ learner.The follow prgram produces a wrong result,but I can't find the wrong.Can you help me?Thank you! #include<stdio.h> long factorial( long number); int main() { int...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.