Concept explainers
c++
I can't get this
//This program will ask user to input a positive integer , then calculates factorial of that number
//Name:
//Date
// if number is 5, then fact 5 is 5* 4 * 3 * 2 * 1
#include <iostream>
using namespace std;
int main()
{
int num; //get user number
int i; // controls the loop
char resp='y'; // get user wish
int fact = 1; // to store factorial of the number
do
{
cout << "Dear user , input a positive number " << endl;
cin >> num;
if (num < 0)
cout << " This is a negative number, i need a positive number" << endl;
else
{
if (num == 0 || num == 1)
cout << " factorial of this number is ====> 1" << endl;
else
{
for (i = 1; i <= num; i++)
fact = fact * i;
cout << " factorial of this number is ====> " << fact<<endl;
}
}
cout << "Would you like to try my program again? y, Y , any other character , terminates the program" << endl;
cin >> resp;
} while (resp == 'Y' || resp == 'y');
system("pause");
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- #include <iostream>#include <iomanip> //For setprecisionusing namespace std; int main() { #enter code herereturn 0;} ****Write in C++ Please.arrow_forwardcommas.cpp) Write a program that accepts a 7-9) digit//integer and echoes the number with commas between every//three digits from the right. Test it with the numbers//, 20300045, & 10000000 c++ // program inserts comas into number given #include <iostream>using namespace std;int main(){int leadingDigits,middledigits,lastdigits;int tempValue,original;cout<< "please enter a 7-9 digit number.\n";cin>>original;tempValue=original/1000;lastdigits=original%1000; // add code lastdigits=original%100; // corrected codeleadingDigits=tempValue/1000;middledigits=tempValue%1000; // add code middledigits=tempValue%100; // corrected code cout<<"the number with comas is "<<leadingDigits;cout<< ","<<middledigits/1<< "," <<lastdigits/1<<endl; // correct this to print individual digits of middle and last digitsreturn 0;}arrow_forward#include <iostream> #include <cmath> using namespace std; // declare functions void display_menu(); void convert_temp(); double to_celsius(double fahrenheit); double to_fahrenheit(double celsius); int main() { cout << "Convert Temperatures\n\n"; display_menu(); char again = 'y'; while (again == 'y') { convert_temp(); cout << "Convert another temperature? (y/n): "; cin >> again; cout << endl; } cout << "Bye!\n"; } // define functions void display_menu() { cout << "MENU\n" << "1. Fahrenheit to Celsius\n" << "2. Celsius to Fahrenheit\n\n"; } void convert_temp() { int option; cout << "Enter a menu option: "; cin >> option; double f = 0.0; double c = 0.0; switch (option) { case 1: cout << "Enter degrees Fahrenheit: "; cin >> f; c =…arrow_forward
- ?If possibly to do it in C please or C++arrow_forwardC Programming What does the below output? #include <stdio.h> #include <string.h> #define MAX_USER_INPUT 100 void main(void) { char char1 = 'A'; char *ptr1; char **ptr2; char ***ptr3; ptr1 = &char1; ptr2 = &ptr1; ptr3 = &ptr2; printf("\nptr3 = %c\n", ***ptr3); }arrow_forward#include <iostream> #include <cmath> using namespace std; // declare functions void display_menu(); void convert_temp(); double to_celsius(double fahrenheit); double to_fahrenheit(double celsius); int main() { cout << "Convert Temperatures\n\n"; display_menu(); char again = 'y'; while (again == 'y') { convert_temp(); cout << "Convert another temperature? (y/n): "; cin >> again; cout << endl; } cout << "Bye!\n"; } // define functions void display_menu() { cout << "MENU\n" << "1. Fahrenheit to Celsius\n" << "2. Celsius to Fahrenheit\n\n"; } void convert_temp() { int option; cout << "Enter a menu option: "; cin >> option; double f = 0.0; double c = 0.0; switch (option) { case 1: cout << "Enter degrees Fahrenheit: "; cin >> f; c =…arrow_forward
- #include using namespace std; main () { for (n = 5;n > e; n--) cout << n<<" "; int int n; %3D { if (n == 3) break; 543 53 554 O 567arrow_forwardC++arrow_forward#include using namespace std; int main() { int g; g = 0; while (g >= −6) { } Type the program's output } cout << g << endl; g = g - 4; return 0;arrow_forward
- #include <iostream> using namespace std; void times(int& prod, int mpr, int mcand) { prod = 0; while (mpr != 0) { if (mpr % 2 == 1) prod = prod + mcand; mpr /= 2; mcand *= 2; } } int main(){ int product, n, m; cout << "Enter two numbers: "; cin >> n >> m; times(product, n, m); cout << "Product: " << product << endl; return 0; } Convert the product into pep9 assembly language.arrow_forward// Swap.cpp - This program determines the minimum and maximum of three values input by // the user and performs necessary swaps. // Input: Three int values. // Output: The numbers in numerical order. #include <iostream> using namespace std; int main() { // Declare variables int first = 0; // First number int second = 0; // Second number int third = 0; // Third number int temp; // Used to swap numbers const string SENTINEL = "done"; // Named constant for sentinel value string repeat; bool notDone = true; //loop control // Get user input cout << "Enter first number: "; cin >> first; cout << "Enter second number: "; cin >> second; cout << "Enter third number: "; cin >> third; while(notDone == true){ // Test to see if the first number is greater than the second number // Test to see if the second number is greater than the third number // Test to…arrow_forward// SumAndProduct.cpp - This program computes sums and products // Input: Interactive// Output: Computed sum and product #include <iostream>#include <string>void sums(int);void products(int);using namespace std; int main() { int number; cout << "Enter a positive integer or 0 to quit: "; cin >> number; while(number != 0) { // Call sums function here // Call products function here cout << "Enter a positive integer or 0 to quit: "; cin >> number; } return 0;} // End of main function// Write sums function here// Write products function herearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education