Question

Create a C++ Program that prompts the user to enter a number and compute for the...

Create a C++ Program that prompts the user to enter a number and compute for the factorial value.

SAMPLE OUTPUT:

ENTER A NUMBER: -5
zero & positive numbers only!!!


ENTER A NUMBER: 5
Factorial of 5 : 5*4*3*2*1 = 120

DO NOT USE FUNCTION FOR THIS PROBLEM. THANK YOU

  

Homework Answers

Answer #1

//c++ program for factorial
#include<iostream>
using namespace std;
int main()
{
int n,i;
unsigned long long factorial = 1;
cout << "ENTER A NUMBER : ";
cin >> n;
if(n==0) //if n==0 printing 1
{
   cout << "Factorial of " << n << " = " << factorial;
}
else if(n>0)
   {
   for(i = 1; i<=n; ++i)   
   {
   factorial=factorial*i; //calculating factorial
   }
cout << "Factorial of " << n << " = " << factorial;   
   }
else
   cout<<"zero & positive numbers only!!!";
return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using C++ design a program that Prompts the User to enter 4 Numbers, then have the...
Using C++ design a program that Prompts the User to enter 4 Numbers, then have the program output those numbers entered in Ascending order. Use "if" statements to create the code...
design a program that prompts the user to enter a positive integer number and reads the...
design a program that prompts the user to enter a positive integer number and reads the user’s input. If the user input is not a positive number, the program should prompt them repeatedly until they enter a valid input. Once a valid input is received ,the program uses a loop to calculate the sum of the digits of the user’s input and displays the sum. For example, if the user enters the number 94311, the program should print the sum...
PLease code a C++ program that prompts a user to enter 10 numbers. this program should...
PLease code a C++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the 10 numbers and the average of the 10 numbers please use file i/o and input measures for Handling Errors in C++ When Opening a File
Write a program that prompts the user for the number of values for which it will...
Write a program that prompts the user for the number of values for which it will calculate the base 2 log of each value. Use a for loop to iterate the set of values and print the log for each. Here is the formula to change the base of a log: loga b = log10 b / log10 a Sample output appears below. This program will calculate the Base 2 log of a set of numbers<LINERETURN> ===============================================================<LINERETURN> Enter the upper...
Python: Write a program that prompts the user to enter a positive integer value, and compute...
Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message containing the word Error and exit the program....
Write a program that prompts the user to enter a string and displays the number of...
Write a program that prompts the user to enter a string and displays the number of characters it contains, fourth character, and last character. Note: The string may contain blanks. For example: “C++ programming is fun”. You should write a complete program.
Create a program that prompts the user for an integer number and searches for it within...
Create a program that prompts the user for an integer number and searches for it within an array of 10 elements. What is the average number of comparisons required to find an element in the array? in java
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
Assembler lanaguage program   The program is to prompt the user to enter a number between 2...
Assembler lanaguage program   The program is to prompt the user to enter a number between 2 and 100. Reject any invalid user inputs and terminate the program if invalid inputs are entered. Print each even number from 2 to the user entered number. Sum these even numbers and print the sum. Print each odd number from 1 to the user entered number. Sum these odd numbers and print the sum. Exit the program when the output is complete. The output...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT