factorial series, C/C++ Programming

1)      Factorial (for this question just provide an answer for each part)

 1.1  Debug the following program to calculate N!

#include

using namespace std;

main()

{

            int N, factorial=1;

            cout << "Enter a positive integer"

            cin >> N;

            for(int i=N; i>=1; factorial *= --i);

            cout << N<<"!="<

return 0;

}

What was wrong?

1.2  Set N='A'. What is the result? Does it make sense? Modify the program to make sure that the entered value is numeric.

Also, modify the program such that it does not accept negative numbers and insists on getting a positive value for N. You can do so by using a while loop that keeps asking for a positive integer till a positive integer is entered.

1.3  Get your code to compute 1!,2!,5!, and 25!. Are you getting the correct answer for all of the entered values? If not, what went wrong? Would you be able to fix this by changing the variable type? Explain your answer.

Posted Date: 2/15/2013 7:33:31 AM | Location : United States







Related Discussions:- factorial series, Assignment Help, Ask Question on factorial series, Get Answer, Expert's Help, factorial series Discussions

Write discussion on factorial series
Your posts are moderated
Related Questions
Need help in network programming in C++ project. How much you charge?

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

C Program to FIND VOWELS   void main() {           char str[50];           int ac=0, ec=0, ic=0, oc=0, uc=0;           int i,stln,vc,word=1;           clrscr

How much does it cost to complete a C++ assignment that is 80% finished??

Project Description: collect / modify person records / photo images/ lookup / facebook iphone and ipad App basic function : 1 user will configure facebook connection

(c) A static member function can access static member data only, static member functions and functions and data outside the class. A static member function may be called, even whil

Problem 1. Discuss polymorphism in c++. Explaining Polymorphism 2. Write a program in c++ to read a 3X2 matrix and find smallest number in that matrix. Writin

Although we can handle most I/O routines with getc and putc , there are file versions of fgets, fputs, fprintf and fscanf . The syntax is       fgets(stringname,n,filename);   Th

write a program in c/C++ using nested if statement for calculating the average marks and grades of 5 subjects

complex coding with structure and file handling