Question

In: Computer Science

Method calling in c# I need to write methods for calling the min and max numbers...

Method calling in c#

I need to write methods for calling the min and max numbers using this code;

Console.WriteLine("Calling highest method.");
Console.WriteLine("Highest number is: {0}", highest(3));
Console.WriteLine("Calling lowest method.");
Console.WriteLine("Lowest number is: {0}", lowest(3));

Solutions

Expert Solution

Program1:

//Finding the highest and lowest number from an array with given size 3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MethodsDemo
{
class Program
{
public static int highest(int num)
{
int[] arr = new int[num];
  
Console.WriteLine("Enter 3 numbers: ");
for (int i = 0; i <= 2; i++)
{
arr[i]=Convert.ToInt32(Console.ReadLine());
}
int high = arr[0];
for (int i=0;i<=2;i++)
{
if (high < arr[i])
{
high = arr[i];
}
}
return high;
}
public static int lowest(int num)
{
int[] arr = new int[num];
  
Console.WriteLine("\nEnter 3 numbers: ");
for (int i = 0; i <= 2; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
int low = arr[0];
for (int i = 0; i <= 2; i++)
{
if (low > arr[i])
{
low = arr[i];
}
}
return low;
}

static void Main(string[] args)
{
Console.WriteLine("Calling highest method.");
Console.WriteLine("Highest number is: {0}", highest(3));
Console.WriteLine("Calling lowest method.");
Console.WriteLine("Lowest number is: {0}", lowest(3));
Console.ReadKey();
}
}
}

Program2:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MethodsDemo
{
class Program
{
public static int highest(int high)
{
return high;
}
public static int lowest(int low)
{
return low;
}

static void Main(string[] args)
{
Console.WriteLine("Calling highest method.");
Console.WriteLine("Highest number is: {0}", highest(3));
Console.WriteLine("Calling lowest method.");
Console.WriteLine("Lowest number is: {0}", lowest(3));
Console.ReadKey();
}
}
}

Note:

In the given question you didn't mention what we have to do so i am going with 2 programs with given contents.

I hope that will be helpful.


Related Solutions

Using the ListNode file. Write methods called min and max that return the smallest and largest...
Using the ListNode file. Write methods called min and max that return the smallest and largest values in the linked list. These methods will be added to your ListNode class. For example if a variable called list stores {11, -7, 3, 42, 0, 14], the call of list.min() should return -7 and the call of list.max() should return 42. If the list is empty, return -1. Print the returned value. Write a method called insertNode that inserts a new node...
Write a C program/code that prompts the user for a minimum min and a maximum max....
Write a C program/code that prompts the user for a minimum min and a maximum max. Then use these values to print the squares of all even numbers between the min and max variables. For example if the user enters 6 as the minimum and 200 as the maximum, the program/code should print the following. Enter limit on minimum square: 6 Enter limit on maximum square: 200 36 64 100 144 196
Find MIN. Write a C# console app consisting of class MIN with the method CalculateMin() and...
Find MIN. Write a C# console app consisting of class MIN with the method CalculateMin() and the driver class. Print the MIN and MIN's location. Don't count numbers outside the range [0, 100].
Write a program/code that prompts the user for a minimum min and a maximum max. Then...
Write a program/code that prompts the user for a minimum min and a maximum max. Then use these values to print the squares of all even numbers between the min and max variables. (WRITTEN IN C) For example if the user enters 6 as the minimum and 200 as the maximum, the program/code should print the following. Enter limit on minimum square: 6 Enter limit on maximum square: 200 36 64 100 144 196
In MIPS assembly language, write a function that will display the max and min value in...
In MIPS assembly language, write a function that will display the max and min value in an array. Then write a function to calculate and display the average of all values in an array. This must be done in MIPS assembly language.
if I need to get the sum of 6 numbers, here is a C programming solution...
if I need to get the sum of 6 numbers, here is a C programming solution int getSum(int number1, int number2, int number3, int number4, int number5, int number6); and the function is: int SUM; sum = number1+number2+number3+number4+number5+number6; return SUM; this function is called in main, and the main looks like: int totalSum; totalSum=getSum(1,2,3,4,5,6); while(1); so how can I write this C programming code in ARM assembly code, can you please write the comment of each line so I can...
Write a method that returns the result when the calling object is multiplied by a scalar...
Write a method that returns the result when the calling object is multiplied by a scalar value. For example, the PolyTerm 2.4x^3 multiplied by -1.2 should return the PolyTerm object representing -2.88x^3. Language: Java. Method name be like: scalarMultiply(double) Some Outputs: Test 1: Coefficient =1, Exponent = 1 scalarMultiply(1.2).coefficient return 1.2; scalarMultiply(1.2).exponent returns 1. Test 2: Coefficient =2.4, Exponent = 3 scalarMultiply(-1.2).coefficient returns -2.88 scalarMultiply(-1.2).exponent return 3 Test 3: Coefficient =-1.5 Exponent = 0 scalarMultiply(0).coefficient returns 0 scalarMultiply(0).exponent returns 3...
I need to write a research paper on the methods used by forensic accountants to discover...
I need to write a research paper on the methods used by forensic accountants to discover corporate fraud. I want to find out how corporate governance uncovered scandals like Enron and WorldCom. Are there any pointers, example outlines, or research suggestions to be able to write a 5-7 paper on the subject?
I need to make 3 or 4-min video about the topic below. Just write script is...
I need to make 3 or 4-min video about the topic below. Just write script is fine. These are some considerations. Describe the new policy that you want Justify why your selection should be implemented with evidence and research Research possible policies This is kind of a persuasive presentation TOPIC: If you were implementing one new policy in Australia, with the aim of making the Australian population happier, what would it be and why?
Write a C++ program to read a collective of integer numbers. I f the number is...
Write a C++ program to read a collective of integer numbers. I f the number is greater than zero and less than 15 then terminate the loop and find factorial of the number
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT