This program can be used to print any multiplication table until any number
using System;
namespace SamplePrograms{ class NumberTable { public static void Main() { // Prompt the user to enter number for multiplication table Console.WriteLine("For which number do you want to print multiplication table");
// Read the number from console and convert to integer int Number = Convert.ToInt32(Console.ReadLine());
// Prompt the user for multiplication table target Console.WriteLine("What is your target? 10, 20, 30 etc...");
// Read the target from console and convert to integer int Target = Convert.ToInt32(Console.ReadLine());
// Loop to print multiplication table until we reach the target for (int i = 1; i <= Target; i++) { // Compute multiplication result int Result = Number * i;
// Format and Print the multiplication table Console.WriteLine(Number.ToString() + " X " + i.ToString() + " = " + Result.ToString());
// The above line can also be rewritten as shown below. // Console.WriteLine("{0} X {1} = {2}", Number, i, Result); } } }}
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.