Question

(1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a funct

c++ please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

#include <iostream>
#include <cmath>
using namespace std;

int CubicRoot(int N)
{
   return pow(N,1.0/3.0);
}
int main() {
  
   int N;
   cout<<"Enter an integer N : ";
   cin>>N;
  
   cout<<"\nThe cubic root of "<<N<<" is "<<CubicRoot(N);
  
   return 0;
}

Output:

Enter an integer N : 27

The cubic root of 27 is 3

2.)

#include <iostream>
#include <cmath>
using namespace std;

bool Even(int N)
{
   if(N %2 == 0) // divisble by 2
   return true;
   else
   return false;
}
int main() {
  
   int N;
   cout<<"Enter an integer N : ";
   cin>>N;
  
   if(Even(N))
   cout<<"\nThe number "<<N<<" is even";
   else
   cout<<"\nThe number "<<N<<" is odd";
  
   return 0;
}

Output:

Enter an integer N : 277

The number 277 is odd

3)

#include <iostream>
using namespace std;

double Mean(int N,double M)
{
   return (N+M)/2;
}
int main() {
  
   int N;
   double M;
  
   cout<<"Enter an integer N : ";
   cin>>N;
   cout<<"\nEnter a number M : ";
   cin>>M;
  
   cout<<"\nThe mean between "<<N<<" and "<<M<<" is "<<Mean(N,M);
  
   return 0;
}

Output:

Enter an integer N : 56
Enter a number M : 78.5
The mean between 56 and 78.5 is 67.25

4)

#include <iostream>
using namespace std;

int Factorial(int N)
{
   int fact = 1;
   for(int i=N;i>=1;i--)
   fact = fact*i;
  
   return fact;
}
int main() {
  
   int N;
  
   cout<<"Enter an integer N : ";
   cin>>N;
  
  
   cout<<"\nThe factorial of "<<N<<" is "<<Factorial(N);
  
   return 0;
}

Output:

Enter an integer N : 5
The factorial of 5 is 120

Do ask if any doubt. Please upvote.

Add a comment
Know the answer?
Add Answer to:
c++ please (1) Write a program that prompts the user to enter an integer value N...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ only Implement a program that prompts a user to enter a number N where N...

    C++ only Implement a program that prompts a user to enter a number N where N is a positive number. The program must validate a user input and ask a user to re-enter until an input is valid. Implement a function that pass N as an argument and return a result of calculates N! (N-factorial): The function must use loop for the implementation. Hint: Factorial: N! = N * (N-1) * (N-2) * …. * 1 ( This is only...

  • C++ Problem #1 Write a program that prompts user to enter an integer up to 1000...

    C++ Problem #1 Write a program that prompts user to enter an integer up to 1000 and displays back a message about the number of digits in this number and if number is odd or even. For example, if user enters 93 message back should be "93 has 2 digits and is odd".

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Write a C program to do the following 1) request user to enter 10 integer into...

    Write a C program to do the following 1) request user to enter 10 integer into an array 2) sort the array in ascending order 3) display the sorted array 4) count the number of odd and even number in the array and print out the result 5) add the value of the odd number and even number and calculate the average of the odd and even number. display the result 6) write function addNumber() to add all the number...

  • Write a program in visual c# program named CheckMonth that prompts a user to enter a...

    Write a program in visual c# program named CheckMonth that prompts a user to enter a birth month. If the value entered is greater than 12 or less than 1, display an error message; otherwise, display the valid month with a message such as 3 is a valid month.

  • 1. Palindrome Write a program that prompts the user for a positive integer number and output whet...

    Language is C 1. Palindrome Write a program that prompts the user for a positive integer number and output whether the number is a palindrome or not. A palindrome number is a number that is the same when reversed. For example, 12321 is a palindrome; 1234 is not a palindromoe. You will write a function named as palindrome. The function will have two arguments, number and isPalindrome. Both arguments are pass-by-reference. The argument number is a pointer to a variable...

  • Write a program that (in the main program) prompts the user for the (integer) model number...

    Write a program that (in the main program) prompts the user for the (integer) model number of their car. The main function should then call the function check defective which should • take in the model number of the car • check if the model number is 119, 179, 221, 780, or anything between 189 and 195, inclusive, which indicates the car is defective • print a message indicating whether or not the car is defective Note: this is should...

  • Write a program that prompts the user to enter an integer, n , and then n...

    Write a program that prompts the user to enter an integer, n , and then n floating point numbers. As the numbers are read, the program will calculate the average of the negative numbers. In C language.

  • Using C++ language P2-4 Write a program that randomly generates an integer and then prompts the...

    Using C++ language P2-4 Write a program that randomly generates an integer and then prompts the user to guess the number. If the user guesses the number correctly, the program outputs an appropriate message such as "You win!" and terminates. Otherwise, the program checks and tell the user whether the guessed number is less or greater than the target number and then prompts him for another try. However, the program gives the user five tries only to guess the correct...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT