Question

In: Computer Science

Write a function called is_equal(). This function will take as an argument two integers. Call the...

  1. Write a function called is_equal(). This function will take as an argument two integers.

  2. Call the is_equal function and supply two integers. You do not need to get the integers from the keyboard.
  3. Compare the two integers. If the two integers are equal, then print "equal". If the two integers are not equal, print "not equal".

  4. Call the function from your main code to execute the function.

Sample output:

equal

Sample output:

not equal

Solutions

Expert Solution

Here our task is to create a function called 'is_equal' which check the equality between two integers and print apropriate result

points to remember

  • Our function need two integer argument (Two recive two integers)
  • we can use if-else statements to check the in equality and take apropriate decision
  • '==' operator is used for checking the eqality
  • if '==' operator returns true then body of if execute otherwise body of else execute
  • printing can doen by using 'cout'

(You didnt mentioned any specific language to code this,hence i assume any language is fine .If you need code in a specific language please repost the question mentioning the language you need help with)

Now let's see how to code this in C++

CODE

(Please read all comments for tthe better understanding of the program)

SAMPLE RUN

I am also attaching the text version of the code in case you nee to copy paste

#include <iostream>

using namespace std;


void is_equal(int x,int y){ //'is_equal' function definition
if (x==y){ //check whether x is equal to y or not
cout<<"equal"; //if yes print equal
  
}
else{ //if not equal 'Not equal 'will print
cout<<"not equal";
}
}


int main() //main function starts here
{
is_equal(10,10); // calling the is_equal function with integer value 10,10

return 0;
}


Related Solutions

In C Write a main function with a function call to a function called GetLetter which...
In C Write a main function with a function call to a function called GetLetter which has two double arguments/parameters. The function returns a character. Declare and initialize the necessary data variables and assign values needed to make it executable and to prevent a loss of information
Write a function called alternate that takes two positive integers, n and m, as input arguments...
Write a function called alternate that takes two positive integers, n and m, as input arguments (the function does not have to check the format of the input) and returns one matrix as an output argument. Each element of the n-by-m output matrix for which the sum of its indices is even is 1. All other elements are zero. For example, here is an example run: >> alternate(4,5) ans = 1 0 1 0 1 0 1 0 1 0...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should display if the argument "is a multiple of 5" or "is not a multiple of 5".
Write a function called HW5_P1 that accepts 1 input argument: an array, a. The function should...
Write a function called HW5_P1 that accepts 1 input argument: an array, a. The function should output an array, b, that is computed as: b=3a+5. Write a MATLAB function called “fit_line” that accepts 2 input arguments: a column vector of x data and a column vector of y data. The nth element in the input arguments should correspond to the nth Cartesian data point i.e. (xn,yn). The function should compute and return 2 outputs: the slope, m, and the y...
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings....
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings. The first string is #the filename of a file to which to write (output_file), and #the second string is the filename of a file from which to read #(input_file). # #In the input file, there will be an integer on every line. #To the output file, you should write the integer from the #original file multiplied by the line number on which it #appeared....
This is python: #Write a function called count_positive_evens. This function #should take as input a list...
This is python: #Write a function called count_positive_evens. This function #should take as input a list of integers, and return as #output a single integer. The number the function returns #should be the count of numbers from the list that were both #positive and even. # #For example: # # count_positive_evens([5, 7, 9, 8, -1, -2, -3]) -> 1 # count_positive_evens([2, 4, 6, 8, 10, 12, 15]) -> 6 # count_positive_evens([-2, -4, -6, -8, -10, 1]) -> 0 # #0...
Write a function called HowMany(), which counts the occurrences of the second argument which is a...
Write a function called HowMany(), which counts the occurrences of the second argument which is a single character in the first argument which is a string. This function should have 2 arguments, the first one is a string and the second argument is a character. For example, the following function : i = count("helloyoutwo", 'o'); would return i= 3. Test your function in a complete code. Language: c++
In C: Write a function definition called PhoneType that takes one character argument/parameter called phone and...
In C: Write a function definition called PhoneType that takes one character argument/parameter called phone and returns a double. When the variable argument phone contains the character a or A print the word Apple and return 1099.99 When phone contains anything else return a 0.0
In C++, create a function exchangesl that takes an argument of an array of integers (...
In C++, create a function exchangesl that takes an argument of an array of integers ( for C++ use implement void exchangesl(vector<int>& a) . Those integers need to be changed so that the smallest and largest values in the array are exchanged. Assume that there is at least one element, if the largest value occurs more than once then exchange the first instance, if the smallest value happens more than once then exchange the last instance.
In C++, create a function exchangesl that takes an argument of an array of integers (...
In C++, create a function exchangesl that takes an argument of an array of integers ( for C++ use implement void exchangesl(vector<int>& a) . Those integers need to be changed so that the smallest and largest values in the array are exchanged. Assume that there is at least one element, if the largest value occurs more than once then exchange the first instance, if the smallest value happens more than once then exchange the last instance. Use the following file:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT