in c# write a method in a mathclass that accepts variable number of integers.method should find the sum of all integers parsed and display the result.write a client program to call the method with variable number of integers.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MathclassApplication
{
class Mathclass
{
public int[] numbers = new int[100];
public int number;
public void inputNumber(int number) {
this.number = number;
for (int i = 0; i < number; i++) {
Console.Write("Enter number "+ (i+1)+": ");
numbers[i] = int.Parse(Console.ReadLine());
}
}
private double getSum()
{
double sum = 0;
for (int i = 0; i < number; i++)
{
sum += numbers[i];
}
return sum;
}
public void ShowResult()
{
Console.Write("Thee sum is: " + getSum().ToString());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MathclassApplication
{
class Program
{
static void Main(string[] args)
{
int number = 0;
Mathclass Mathclass = new Mathclass();
Console.Write("Enter number of numbers: ");
number = int.Parse(Console.ReadLine());
Mathclass.inputNumber(number);
Mathclass.ShowResult();
Console.ReadLine();
}
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C#