Question

C++ PROBLEM: Create a program that calculates the hyperfactorial of any positive integer n, where the...

C++ PROBLEM:

Create a program that calculates the hyperfactorial of any positive integer n, where the hyperfactorial is equivalent to value obtained by the operation: 1^1*2^2*3^3*…..n^n . If user inputs the value that is not a positive value, display a message informing the user that the input is not valid and request a new input. Calculate the hyperfactorial first by creating a program that uses only nested “For loop” structure.

Homework Answers

Answer #1

C++ code:

#include<iostream>

using namespace std;

int main(){

// Declarig a varibale to store hyperfactorial

long long int hf = 1;

// Asking the user to enter n

int n;

cout << "Enter n: ";

cin >> n;

// Checking for condition

while(n <= 0){

cout << "n should be > 0" << endl;

cout << "Enter n: ";

cin >> n;

}

// Running nested for loop to calculate hf

for(int i = 1; i <= n; ++i){

for(int j = 1; j <= i; ++j){

hf *= i;

}

}

// Displaying the hyperfactorial

cout << "Hyperfactorial of a number is " << hf << endl;

return 0;

}

OUTPUT:

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
Develop a C++ program that determines the largest and second largest positive values in a collection...
Develop a C++ program that determines the largest and second largest positive values in a collection of data Prompt the user to enter integer values until they enter any negative value to quit You may presume the user will input at least two valid integer values Create a loop structure of some sort to execute this input cycle Maintain the largest and second largest integer as the user inputs data This logic should be placed inside your loop structure Arrays...
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You...
(Python Programming) Write a program that prompts a user for a positive integer and then uses...
(Python Programming) Write a program that prompts a user for a positive integer and then uses a loop to calculate and display the sum of specific fractions as follows: Let's say the user enters 5, then your program will compute: 1/5 + 2/4 + 3/3 + 4/2 + 5/1 which is 8.7.
For any integer n > 0, n!(n factorial) is defined as the product n * n...
For any integer n > 0, n!(n factorial) is defined as the product n * n - 1 * n − 2 … * 2 * 1. And 0! is defined to be 1 Create function that takes n as input and computes then returns the accurate value for: n!= n * n - 1 * n − 2 … * 2 * 1 prompt the user to enter an integer n, call functions to compute the accurate value for...
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
Using a loop (not the output format character %o), create a program that takes a positive...
Using a loop (not the output format character %o), create a program that takes a positive integer n, and then displays the polynomial for the octal representation of that integer. Use successive division, as demonstrated in the binary conversion example from the lesson, to do this. For example, for n = 157, the program should output the following: 157 = + (5 * 8^0) + (3 * 8^1) + (2 * 8^2) When this part is working properly, “surround” this...
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For...
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For Loop that asks for a number between 1 and 10; Will double the number each time through the loop and display the answer. Will run five times, so the number will have been doubled five times, and the answer displayed five times. After the loop, display a message saying 'It's done!'. 2. Uses a While Loop; Ask the user to input a friend's name....
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
Collapse Write a program that prompts the user to input a positive integer. It should then...
Collapse Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd integer is prime if it is not divisible by any odd integer less than or equal to the square root of the number.) Turn in: Your source code for with The name of your program as a comment at the top...