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
Operator Overloading Fundamentals The C language uses the concept of Operator Overloading discreetly. The asterisk (*) is used as multiplication operator as well as indirect


Define the Volatile Keyword Qualifiers in C Language? The volatile keyword proceed as a data type qualifier and a volatile variable is for dynamic use. E.G. for data that is to

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

Project Description: Need to develop an expert advisor base on sthocastic oscilator with my own setting.. Very basic touch line OB/OS only but on my setting n condition Skill


assume that the first integer read with cin specifies the number of values remaining to be entered. that program should read only one value each time cin is executed .a typical inp

1 Aims The main purpose of the assignment is to let you practice the following programming techniques: perform operations on pointers to basic and more complex types;

Hi I''m trying to connect to CISCO router using termios. So I decided to have two threads one for reading data and the other one for writing data. The problem is that I have to add

traffic light t junction I have 21 LEDs will 6 in each side 3 for the cars the other 3 will be for the people across the street this will be for each side and the last 3 for show