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...
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
c++ Write a program that print stars, Max and Min values. It should use the following...
c++ Write a program that print stars, Max and Min values. It should use the following functions: (2 pts) int getNum ( ) should ask the user for a number and return the number. This function should be called by main once for each number to be entered. Input Validation: Do not accept numbers less than -100. (2 pts) void printStars ( int n ) should print n number of stars. If n is less than 0, display "Invalid" message...
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].
I need it in java. Write a program that will print if n numbers that the...
I need it in java. Write a program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT