The document describes 7 methods to: 1) Calculate the summation of integers, 2) Get the factorial of a number, 3) Get the maximum of 3 integers, 4) Check the sign of a number, 5) Check if a number is odd or even, 6) Act as a calculator for basic math operations, and 7) Accept a name and print it inverted. Sample code is provided for each method. A note at the end instructs the reader to write a Main method to call the other methods.
The document describes 7 methods to: 1) Calculate the summation of integers, 2) Get the factorial of a number, 3) Get the maximum of 3 integers, 4) Check the sign of a number, 5) Check if a number is odd or even, 6) Act as a calculator for basic math operations, and 7) Accept a name and print it inverted. Sample code is provided for each method. A note at the end instructs the reader to write a Main method to call the other methods.
• Calculates the summation of any n integer values. • Gets the factorial of any integer number. • Gets the maximum of any three integers. • Checks the sign of a number. • Checks if a number is odd or even. • Acts as a Calculator to get the summation, production, difference and division of two number. • Accepts your name and prints it inverted.
Solution: Method1:
static int summ(int n) {
int result = 0, input=0; for(int i = 1; i <= n; i++) { Console.WriteLine("Enter number {0} ",i); input = int.Parse(Console.ReadLine()); result += input; } return result; } Method2:
static int fact(int n) {
int factorial = 1; for (int i = 1; i <= n; i++) { factorial *= i; } return factorial;} Method3:
static int max(int x,int y,int z)
{ int maximum = x; if (y > x && y > z) { maximum = y; } else if (z > x && z > y) { maximum = z; } return maximum; } Method4:
static void sign(double s)
{ if (s > 0) Console.WriteLine("Positive"); else if (s < 0) Console.WriteLine("Negative"); else Console.WriteLine("Equal 0"); }