Question

(SHORT ANSWER) Define a function named halfNum that has one integer paramétel half of the number For example: If we called th

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

#include <iostream>
using namespace std;

float halfNum(int number)
{
   return (float)number/2; // casting int number to float data type and then dividing by 2
}
int main() {
   int num;
   cout<<"Enter the number : ";
   cin>>num;
  
   cout<<"\nHalf of number : "<<halfNum(num);
  
  
   return 0;
}

output:

Enter the number : 1
Half of number : 0.5

Do ask if any doubt. Please up-vote.

Add a comment
Know the answer?
Add Answer to:
in c++ (SHORT ANSWER) Define a function named halfNum that has one integer paramétel half of...
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
  • python programming X Canvas 4 → XCO Question 26 10 pts (SHORT ANSWER) Define a function...

    python programming X Canvas 4 → XCO Question 26 10 pts (SHORT ANSWER) Define a function named find_even_odd that has 1 parameter: num. When the function is called, it should use an if/else statement to determine whether the variable num is an even or odd number and display appropriate message as follows: • If the value in num is an even number, the progr will output the message: "XX is an EVEN number", where XX is the value in the...

  • Define a function named insert that takes an integer atom and a sorted list as parameters....

    Define a function named insert that takes an integer atom and a sorted list as parameters. The function should return a list with the integer in the correct position in the sorted list. For example: insert [3, (2 4 6 8)] = (2 3 4 6 8) insert 9, ()] = (9) insert[3, (2 3 4 5)] = (23 3 4 5) Note that in the case of that last example, it does not matter which 3 comes first in...

  • 1. Write a C function named find that receives a one-dimensional array of type integer named...

    1. Write a C function named find that receives a one-dimensional array of type integer named arr and its size of type integer. The function fills the array with values that are the power of four (4^n) where n is the index. After that, the function must select a random index from the array and move the array elements around the element stored in the randomly selected index Example arr = [1, 4, 16, 64, 256) if the randomly selected...

  • python programming Question 29 10 pts (SHORT ANSWER) Define a function named display_pattern that is a...

    python programming Question 29 10 pts (SHORT ANSWER) Define a function named display_pattern that is a void function with no parameters. When the function is called, it should use a nested loop to to display the symbol # in 2 rows and 3 columns as follows: ### ### BI V A - A - I E33 x x, E V GT 12pt Paragraph

  • Define a JavaScript function named activityScore with one parameter. Assume the function will be called with...

    Define a JavaScript function named activityScore with one parameter. Assume the function will be called with an array of Numbers. Define the function so that it creates an Object. This object should have a key equal to "score", and its paired value should be set to the sum of the array’s entries. Return the JSON blob encoding the Object.

  • How to Define a function named calculatePI that takes a positive integer n as its argument...

    How to Define a function named calculatePI that takes a positive integer n as its argument and calculates π using the formula: (Assume n is odd, which is the precondition of the function. And, this function should return double type value.) π = 4*(1 – 1/3 + 1/5 – 1/7 + 1/9 – 1/11 + ... 1/n)

  • Task 4: a) Write a function named change() that has an integer parameter and six integer...

    Task 4: a) Write a function named change() that has an integer parameter and six integer reference parameters named hundreds, fifties, twenties, tens, fives, and ones. The function is to consider the passed integer value as a dollar amount and convert the value into the fewest number of equivalent bills. Using the reference parameters, the function should alter the arguments in the calling function. b) Include the function written in part a in a working program. Make sure your function...

  • Write a C function named date() that receives an integer number of the long date, date...

    Write a C function named date() that receives an integer number of the long date, date form is yyyymmdd, such as 20070412; and the addresses of three variables named month, day, and year. determines the corresponding month, day, and year; and returns these three values to the calling function. For example, if date() is called using the statement     longdate=20200411; date(longdate, &month, &day, &year); the number 4 should be returned in month, the number 11 in day, and the number...

  • IN PYTHON Define a python function named remain to take two integer parameters and return the...

    IN PYTHON Define a python function named remain to take two integer parameters and return the remainder when the first integer is divided by the second. Multiple lines of code are required. Indicate indention when necessary with a few taps of the spacebar.

  • 2. Define a class named “Holiday” that manages one holiday info such as month (integer), day...

    2. Define a class named “Holiday” that manages one holiday info such as month (integer), day (integer) and name (string). For example, 7, 4 and “Independence Day” • “toString” method to return holiday info as a string in the format: holiday name (month/day). For example, “Independence Day (7/4)” • “isLater” method that compares with another Holiday object and return true if the date of the holiday is later (month and day) and false otherwise. • “getMonth” method to return the...

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