68 393
Assignments Done
98,5%
Successfully Done
In December 2018

Answer to Question #18011 in C# for nishant

Question #18011
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.
Expert's answer
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions