Question

Create an m-file function called exam2 yourname fun. The function takes as input two values a and b. If a is bigger than b the function returns the product of a and b. If a equals b, the function returns the sum of a and b. And if b is bigger than a, the output should be zero, and a message should be displayed that reads: Value of b = "value of b" bigger than a="value of a" EXAMPLE: If a=2 and b=4 the message should read ”Value of b = 4 bigger than a = 2”

Answer #1

clc;

output = exam2(2,4)

function output = exam2(a,b)

if a > b

output = a*b;

elseif a == b

output = a + b;

elseif b > a

output = 0;

fprintf("Value of b = %d bigger than a = %d",b,a);

end

end

Write C++ code to:
Create a function called “ReadFile” that:
Accepts a filename as input
Opens the file for reading
Reads an integer from the file and returns it.
Create a main function that
Asks the user to input a file
Passes that file to the “ReadFile” function
Prints the returned integer to the screen

Write C++ code to:
Create a function called “ReadFile” that:
Accepts a filename as input
Opens the file for reading
Reads an integer from the file and returns it.
Create a main function that
Asks the user to input a file
Passes that file to the “ReadFile” function
Prints the returned integer to the screen
Extra Credit:
Set a default argument of “intfile.txt” for the “ReadFile”
function
Write an overloaded function of “ReadFile” that accepts two
filenames and reads an...

Using C programming
Create a function called printMenu( ) with the following
properties:
Has no function inputs or output.
Prints the following menu to the screen:
1. Enter user name.
2. Enter scores.
3. Display average score.
4. Display summary.
5. Quit
Create a function called printLine( ) with the following
properties:
Takes as input a char
Takes as input an integer corresponding to the number of
times to print the character
Has no function output.
For example, if we...

IN MATLAB: Write a function file that takes a vector as an input
and returns another vector with all repeated elements of the
original vector. For example, the vector [3 4 1 0 4 -5 7 3] would
return the vector [3 4]. Do not use the built-in function
"repelem."

MATLAB:
Write a function called matrix_problem1 that
takes a matrix A of positive integers as its sole input. If the
assumption is wrong, the function returns an empty matrix.
Otherwise, the function doubles every odd element of A and returns
the resulting matrix. Notice that the output matrix will have all
even elements. For example, the call B = matrix_problem([1 4; 5 2;
3 1], will make B equal to [2 4; 10 2; 6 2]. The function should
work...

asap python:
Write a function called fileCaseSwap that takes 2 filenames
(strings) as input parameters. The function should:
Open the first file for reading
Open the second file for writitng
Read the first file
Swap the case (swapcase) of every character in
the file
Write the replaced text to the second file.
test call:
fileCaseSwap("emma-short.txt", "emma-short-swap.txt")
fileCaseSwap("emma.txt", "emma-swap.txt")
"""
"""
The first 3 lines of the emma-short-swap.txt file should be
emma
bY jANE aUSTEN

C++
create a program that:
in main:
-opens the file provided for input (this file is titled
'Lab_HW10_Input.txt' and simply has 1-10, with each number on a new
line for 10 lines total)
-calls a function to determine how many lines are in the
file
-creates an array of the proper size
-calls a function to read the file and populate the array
-calls a function to write out the contents of the array in
reverse order
*output file should...

Write a function called light_speed that takes as input a row
vector of distances in kilometers and returns two row vectors of
the same length. Each element of the first output argument is the
time in minutes that light would take to travel the distance
specified by the corresponding element of the input vector. To
check your math, it takes a little more than 8 minutes for sunlight
to reach Earth which is 150 million kilometers away. The second
output...

Write a function called sum_half that takes as input a square
matrix A and computes the sum of its elements that are in the upper
right triangular part of A, that is, elements in the diagonal and
elements that are to the right of it. For example, if the input is
[1 2 3; 4 5 6; 7 8 9], then the function would return 26. (That is,
1+2+3+5+6+9) Note, the function triu is not allowed. Please write
as you...

Fill in the code for the function below called
containsAvgValue. It takes as input a
float array of any length and returns 1 if the
array happens to contain a value that equals the average of all the
values in the array or 0 otherwise. For example,
when give the array [2.0, 2.0] it should return 1 since the average
value is 2.0 and the array contains that value. To help you, I’ve
included a function that computes the average...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 7 minutes ago

asked 22 minutes ago

asked 22 minutes ago

asked 30 minutes ago

asked 39 minutes ago

asked 52 minutes ago

asked 53 minutes ago

asked 54 minutes ago

asked 58 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago