C# Programming 7. Write a program that produces a multiplication table with 25 r
ID: 3587571 • Letter: C
Question
C# Programming
7. Write a program that produces a multiplication table with 25 rows of computations. Allow the user to input the first and last base values for the multiplication table. Display a column in the table beginning with the first base inputted value. The last column should be the ending base value entered. The first row should be for 1 times the beginning base. 1 times the (beginning base value + 1), through 1 times the ending base value. The last row should be for 25 times the beginning base, 25 times the (beginning base value + 1), through 25 times the ending base value. Base values can range from 2 to 8. Display an error message if an invalid base is entered. Display an aesthetically formatted multiplication table. An example of output produced when 2 and 8 are entered appears in Figure 6-22. 112 120 128 136 144 152 160 168 112 126 120 120 184 192 200 100 144 168Explanation / Answer
using System;
class MultiplicationTable
{
public static void Main(){
int startBase, endBase;
//Taking inputs from the user.
Console.Write("Please enter FIRST base value between 2 and 8 : ");
startBase = int.Parse(Console.ReadLine());
Console.WriteLine();
Console.Write("Please enter SECOND base value between 2 and 8 (greater then or equall to FIRST base) : ");
endBase = int.Parse(Console.ReadLine());
Console.Write(" ");
//checking if inputs are following the basic rules
//1. Value should fall between 2 and 8
//2. secondBase should be greater than firstBase
if((startBase >=2 && startBase<=8) && (endBase>=startBase && endBase<=8))
{
Console.Write("n");
Console.Write(" ");
//this loop is to print the headings.
for(int i=startBase; i<=endBase; i++)
{
Console.Write(i + " ");
}
Console.WriteLine();
//This loop is to print all the 25 rows.
for(int i=1; i<=25; i++)
{
Console.Write(i + " ");
//This loop multiplies base with the current row value and displays it.
for(int j=startBase; j<=endBase; j++)
{
Console.Write((j*i) + " ");
}
Console.WriteLine();
}
}
else
Console.WriteLine("INVALID BASE (Value is not following mentioned rules)");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.