Program to calculate the n factorial, C/C++ Programming

Assignment Help:

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?

Set N='A'. What is the result? Does it make sense? Modify the program to make sure that the entered value is numeric. You can do so by using cin.fail() and cin.clear() (see the following for more information.

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.

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.


Related Discussions:- Program to calculate the n factorial

Define a complex number in c program, Define a complex number in c program:...

Define a complex number in c program: class complex                                 {                                   private:                                 in

Develop opencv tracking, Help me evaluate suitable OpenCV filters to get an...

Help me evaluate suitable OpenCV filters to get an inital working tracking algorithm. In this case it's objects moving on water (sea) and since I have very limited OpenCV knowledge

Decodethecode.h, decodes the sending smuggler string from the number format...

decodes the sending smuggler string from the number format into plain text

Write a c program to input three real numbers, Write a C program to input f...

Write a C program to input five numbers and print them out on a new line Write a C program to input three real numbers and print them out as follows:   The first variable is

Explain input output function, Input Output Most languages have "statem...

Input Output Most languages have "statements" to perform I/O . Though in C and C++ we use "functions" to perform I/O. C++ also has its own I/O mechanism - the cin and cout obje

C, minimum total number of shelves.

minimum total number of shelves.

Salary of an employe, basic salary of an employe.the allowence are House r...

basic salary of an employe.the allowence are House rent 20% of basic salary Medical allowence is 10% of basic salary conveyence allowence is 10% calculate anrd display gross salar

Design test program that tests the student, This is a test program that tes...

This is a test program that tests the Student and ITECH7603Class classes.     In this assignment you are provided with three input text files associated with this program:

Notion of encapsulation, The purpose of this assignment is to familiarize y...

The purpose of this assignment is to familiarize you with the notion of encapsulation as well as some aspects of IP and ICMP. Write your programs in C or C++. They will be grade

Explain operator overloading fundamentals, Operator Overloading Fundamental...

Operator Overloading Fundamentals The C language uses the concept of Operator Overloading discreetly. The asterisk (*) is used as multiplication operator as well as indirect

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd