Question

Please code C# Write a method with an int return type that has two int parameters....

Please code C#

  1. Write a method with an int return type that has two int parameters. The method returns the larger parameter as an int. If neither is larger, the program returns -1.
    1. Call this method three times, once with the first argument larger, once with the second argument larger, and once with both arguments equal

Homework Answers

Answer #1
using System;
public class main
{
    public static int Greater(int num1, int num2)
    {
        if(num1>num2)
        return num1;
        else if(num1<num2)
        return num2;
        else
        return -1;
    }
     
    public static void Main()
    {
    for(int i=0;i<3;i++)
    {
          Console.Write("Enter a number: ");
      int n1= Convert.ToInt32(Console.ReadLine());
      Console.Write("Enter another number: ");
      int n2= Convert.ToInt32(Console.ReadLine());
      if(Greater(n1,n2)!=-1)
      Console.WriteLine("The Greater of two numbers is : {0} \n", Greater(n1,n2) );
      else
      Console.WriteLine("The two number are same : {0}",Greater(n1,n2));
    }
    }
}    

Here is the program that will asks the user to enter two number for three times by using a for loop and every time will print whether num1 is greater or num2 is greater.If both are same then it prints -1 as output.

SCREENSHOT OF THE OUTPUT :

Know the answer?
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
Similar Questions
[Scala] Write a sorting method in Scala named "sort" that takes two parameters of type Int...
[Scala] Write a sorting method in Scala named "sort" that takes two parameters of type Int and returns an Int: sort(x: Int, y: Int): Int This method should return: -1 if x comes before y 0 if x = y 1 if x comes after y This method should place even values before odd values, and then from largest to smallest. ex (this sequence is sorted with respect to the above ordering rules): (8,6,4,2,0,9,7,5,1) Please use Scala!
1. Please write the following in C++ also please show all output code and comment on...
1. Please write the following in C++ also please show all output code and comment on code. 2. Also, use CPPUnitLite to write all test and show outputs for each test. Write CppUnitLite tests to verify correct behavior for all the exercises. The modifications are aimed at making the exercises more conducive to unit tests. Write a function that swaps (exchanges the values of two integers). Use int* as the argument type. Write a second swap function using a reference...
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as...
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as two parameters and returns a string that is concatenated together n times. (For example, repeatNTimes ("hello", 3) returns "hellohellohello") Write a driver program that calls this method from the Main program. Program should ask for input and be stored in the string and should return n amount of times.
Design, code, and test a program that includes a function of type double called divbaby that...
Design, code, and test a program that includes a function of type double called divbaby that accepts two double arguments (you must write the divbaby function). When called, your function will return the first argument divided by the second argument. Make sure your function includes a decision statement so that it can't divide by 0--if the caller attempts to divide by 0 the function should return a value of -2.0. Your program should call divbaby then display the value returned...
Write in C++ program and write a function named computeCostPlusGST. It should accept two double type...
Write in C++ program and write a function named computeCostPlusGST. It should accept two double type variable as arguments. The first argument should be named cost; the second argument should be named rate. The argument rate should have a default value of 0.15. The function should return by value the value of cost plus the product of cost and rate
Write a recursive method public static int sumEveryOther(int n) that takes a positive int as an...
Write a recursive method public static int sumEveryOther(int n) that takes a positive int as an argument and returns the sum of every other int from n down to 1. For example, the call sumEveryOther(10) should return 30, since 10 + 8 + 6 + 4 + 2 = 30. The call sumEveryOther(9) should return 25 since 9 + 7 + 5 + 3 + 1 = 25. Your method must use recursion.
Write in C++ program and write a function named add. It should accept two const double...
Write in C++ program and write a function named add. It should accept two const double type references as arguments. The first argument should be named num1; the second argument should be named num2. The function should return by value of num1 plus num2.
Write a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost...
Write a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. All items are of type double. If the method is called with 50 20.0 3.1599, the method returns 7.89975. Define that method in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your drivingCost() method three times. Output each floating-point value...
C program. Given the following code: int add_and_double(int a, int b) { int result = (a...
C program. Given the following code: int add_and_double(int a, int b) { int result = (a + b) * 2; return result; } int main() {   int val; val = add_and_double(12, 40); return 0; } where the function main() (i.e. the caller) calls the function add_and_double() (i.e. the callee). Which of the following actions are taken when main() calls the function add_and_double()?  Select all that apply. a. Once the callee returns, the caller frees the stack memory for the callee's function...
Write a method called sumDiagonal() that takes a 2D array of int as an argument returns...
Write a method called sumDiagonal() that takes a 2D array of int as an argument returns the sum of the first element in the first row, the second element of the second row, the third element of the third row, etc. You may assume that the array is not jagged and has at least as many columns as rows.