Code the following two C# programs. In each of the questions, You must design an
ID: 3791169 • Letter: C
Question
Code the following two C# programs. In each of the questions, You must design and use at least one method to keep the Main () method cleaner and easier to understand. Make the output attractive and pleasing. Submit a Word doc which includes the C# codes and the cropped output results (trim-off unrelated parts) for Q1 and Q2. Test and verify your programs other than the data given in the example below.
Q1. Program Description: The program should:
Ask a user to enter some digit (integer) between 1 and 9
Multiply it by 9
Write the output to the screen
Multiply that new number by 12345679 (note the absence of the number 8)
Write that output to the screen.
As shown below, the program should print out the entire multiplication as though you had done it by hand.
-------------------Sample Screen Output:----------------------
Enter a number from 1 to 9: 5
5
X 9
----------------
45
X 12345679
---------------------
555555555 (ßTo look like this, the last number must be an int.)
Note: Your alignment does not need to be perfect, but should roughly approximate what you see above.
---------------------------------------------------------------------
Q2. Program Description: Write a program that prompts the reader for two integers and then prints:
The sum
The difference (This should be number1 minus number2.)
The product
The average (This should be a double number. with decimal point)
Presents the output of two different input sets in the Word doc.
--------------Sample Screen Output:------------------
Enter number 1: 13
Enter number 2: 20
Original numbers are 13 and 20.
Sum = 33
Difference = -7
Product = 260
Average = 16.5
-------------------------------------------------------------
Explanation / Answer
Q1
using System;
public class Test
{
public static void multiply()
{
Console.WriteLine("Enter a number from 1 to 9: ");
int number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" "+number);
Console.WriteLine("X 9");
Console.WriteLine("----------------");
Console.WriteLine(" "+number*9);
Console.WriteLine("X 12345679");
Console.WriteLine("---------------------");
Console.WriteLine(" "+number*9*12345679);
}
public static void Main()
{
multiply(); //call to multiply function
}
}
output:
Q2
using System;
public class Test
{
public static void calculator()
{
Console.WriteLine("Enter number 1: ");
int number1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter number 2: ");
int number2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Original numbers are "+number1 +" and "+number2);
Console.WriteLine("Sum = "+(number1+number2));
Console.WriteLine("Difference = "+ (number1-number2));
Console.WriteLine("Product = "+ number1*number2);
Console.WriteLine("Average = "+ (double)(number1+number2)/2);
}
public static void Main()
{
calculator(); //call to multiply function
}
}
output: