Question

In: Computer Science

Functions Create a function to calculate multiplying 15 with 6 and trace the result. Create a...

Functions

  1. Create a function to calculate multiplying 15 with 6 and trace the result.
  2. Create a function to double the number 20. Have it return to myResults. Trace myResults

Solutions

Expert Solution

a) C program to create function to calculate multiplying 15 with 6

#include <stdio.h>

//function prototype
multiply(int a,int b);


int main()
{
  
//calling function multiply-passing 15 and 6
multiply(15,6);
   
return 0;
}

//function multiply() implementation
multiply(int a, int b)
{
//variable to hold multiplication of two values
int res;
  
//multiplication of a and b
res = a * b;
  
//printing result of a multipled by b
printf("Result=%d",res);
}

Output: Result=90

b) C program to create function to double the number 20

#include <stdio.h>

//function prototype
int doubleValue(int x);

int main()
{
  
//calling function doubleValue-passing 20 and assigning it to result
int result = doubleValue(20);
  
//printing result to console
printf("\nResult=%d",result);
   
return 0;
}

//function doubleValue() implementation
int doubleValue(int a)
{
//variable declaration
int myResults;

//double the number
myResults = 2 * a;

//Have it return to myResults
return myResults;
}

Output: Result=40


Related Solutions

Your Task: Write a calculator Program with following functions (lack of function will result in a...
Your Task: Write a calculator Program with following functions (lack of function will result in a grade of zero). Your program must have the following menu and depending on the users choice, your program should be calling the pertaining function to display the result for the user. 1 - Add 2 - Subtract 3 - Multiply 4 - Divide 5 - Raise X to the power Y 6 - Finds if a number is even or odd 0 - Quit...
Your Task: Write a calculator Program with following functions (lack of function will result in a...
Your Task: Write a calculator Program with following functions (lack of function will result in a grade of zero). Your program must have the following menu and depending on the users choice, your program should be calling the pertaining function to display the result for the user. 1 - Add 2 - Subtract 3 - Multiply 4 - Divide 5 - Raise X to the power Y 6 - Finds if a number is even or odd 0 - Quit...
Take the following program and include overload functions into it. Display result of function. C++ Program:...
Take the following program and include overload functions into it. Display result of function. C++ Program: #include <iostream> using namespace std; // this is the additional function string read() {     string input;     cout << "Enter input: ";     cin >> input;     return input; } int main() {     // call function here     string output = read();     cout << "You entered: " << output; }
Create four anonymous functions to represent the function 6e3cosx2, which is composed of
Create four anonymous functions to represent the function 6e3cosx2, which is composed of the functions h(z) = 6ez, g(y) = 3 cos y, and f(x) = x2. Use the anonymous functions to plot 6e3cosx2 over the range 0 ≤ x ≤ 4.
If it needs more information be specific. JavaScript Functions Create the makeBranches() function that will be...
If it needs more information be specific. JavaScript Functions Create the makeBranches() function that will be used to append node branches to the node tree diagram. The function will have two parameters named treeNode and nestedList. The treeNode parameter stores the current node from the source article and the nestedList parameter stores the structure of the node tree displayed in the web page. Add the commands described in the steps below. Each time the makeBranches() function is called, it is...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of a number. * function name: get_fact * parameters: num (int) * returns: int * operation: Must use a loop here. Essentially calculate and return the factorial of whatever number is provided. but: - If num is less than 1 or greater than 20, print "num is out of range" and exit the function - If num is not an int, print "invalid num parameter"...
construct the trace table or trace table list for the function call CR (111) where the...
construct the trace table or trace table list for the function call CR (111) where the definition of CR () is bool CR ( int n ) { bool w,x,y,z,r; int c; c= 3*n; c + = 16; c=c%5; w=c==4;
For Absorption Costing, I will calculate the Cost of Goods Sold by multiplying the Sales and...
For Absorption Costing, I will calculate the Cost of Goods Sold by multiplying the Sales and (Fixed Manufacturing cost per unit + Variable Manufacturing Cost per unit). The reconciliation should be done using this formula: Net Income (Absorption Costing) - Net Income (Variable Costing) = Fixed Overhead in ending balance - Fixed Overhead in opening balance. Thank you. Medina Corp produces bicycle helmets. Each helmet is sold for $100. Planned and actual production was the same for May and June....
Requirements: In this assignment, you are going to create two switch functions. The first function is...
Requirements: In this assignment, you are going to create two switch functions. The first function is going to be called switchVal and the second is going to be called switchRef. The goal of this assignment is to demonstrate the understanding of what pass-by-reference (Links to an external site.) and pass-by-value (Links to an external site.) do when working with functions that you create. The two functions that you will modify need to accept two parameters and inside them they need...
use C++ to create a function to calculate it. My requirements are very simple: function should...
use C++ to create a function to calculate it. My requirements are very simple: function should be general to deal with any size matrices. That's all.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT