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

C++ write a function called divideBy that takes two integers as its input and returns the...
C++ write a function called divideBy that takes two integers as its input and returns the remainder. If the divisor is 0, the function should return -1, else it should return the remainder to the calling function.
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...
C++ Write a function called gen_dates() that generates random dates. It takes two arrays of integers...
C++ Write a function called gen_dates() that generates random dates. It takes two arrays of integers called months and days to store the month and day of each date generated, a constant array of 12 integers called num_of_days that specify the number of days of each of the 12 months and an integer called size that specifies how many dates to generate and randomly generates size dates, storing the generated months in months array and generated days in days array....
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...
Write a Java function to swap two integers.
Write a Java function to swap two integers.
Write a function called randFill that fills the entries of an array with random integers in...
Write a function called randFill that fills the entries of an array with random integers in the range from 10 to 99 (inclusive). (You should use a standard Java method to generate the values. Your solution should use no more than 6 lines of code.) For example, a program that uses the function randFill follows. public class P4 { public static void main(String args[]) { int x[]; x = randFill(5); for (int i = 0; i < 5; i++) System.out.print(x[i]...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT