Simple program #11 (Source code to print
table of a number)
Enter a number: 5
Table for 5
--------------------
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
The program is written in C#
programming language and will accept a number as input. The logic of the
program is to print table.
Let’s find out a simple and easy way
to code the program.
Practical Implementation:
using System;
namespace patternProblem.Simple_program
{
class Simple11 //table of a number
{
static void Main(string[] args)
{
Console.Write("Enter a number: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Table for " + n);
Console.WriteLine("--------------------");
if (n >= 0)
{
for (int i = 1; i
<= 10; i++)
{
Console.WriteLine("{0} * {1} = {2}", n, i, n * i);
}
}
else
{
Console.WriteLine("Negative number is not
allowed.");
}
Console.ReadKey();
}
}
}
Output:
The input
number is 5. The program will print table for input number. The output is shown
below:
Enter a number: 5
Table for 5
--------------------
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
Press any key to continue . . .
For any query,
comment us below.
Skip to
Main Table Simple program
Keep learning and sharing...
No comments:
Post a Comment