Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Monday, 24 July 2017

Simple program


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.
 
Simple program by imaginationhunt blogs
Simple program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

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

Previous - Simple program #10


Click imagination hunt to read latest blogs.


Keep learning and sharing...
Read More »

Thursday, 20 July 2017

Simple program

Simple program #10 (Source code to calculate factorial of a number)

Enter a number: 5
Factorial of 5 is: 120

The program is written in C# programming language and will accept a number as input. The logic of the program is to find factorial of the input operator.
 
Simple program by imaginationhunt blogs
Simple program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code the program.

Practical Implementation:

using System;

namespace patternProblem.Simple_program
{
    class Simple10   //factorial of a number
    {
        static void Main(string[] args)
        {
            Console.Write("Enter a number: ");
            int n = Convert.ToInt32(Console.ReadLine());
            int factorial = 1;
           
            if (n >= 0)
            {
                for (int i = n; i > 1; i--)
                {
                    factorial = factorial * i;
                }
                Console.WriteLine("Factorial of {0} is: {1}", n, factorial);
            }
            else
            {
                Console.WriteLine("Factorial is -ve number is not possible");
            }
            Console.ReadKey();
        }
    }
}

Output:
The input number is 5. The program will do find factorial of the input operator. The output is shown below:

Enter a number: 5
Factorial of 5 is: 120
Press any key to continue . . .


For any query, comment us below.

Skip to Main Table Simple program

Previous - Simple program #9

Next - Simple program #11

Click imagination hunt to read latest blogs.


Keep learning and sharing...
Read More »

Wednesday, 19 July 2017

Simple program

Simple program #9 (Source code to calculator program)

Enter first number: 5
Enter second number: 6
Choose an operator type from +, -, *, /, %: *
O/p: -
5 * 6 = 30

The program is written in C# programming language and will accept two numbers as input. The logic of the program is to do calculation based on the input operator.
 
Simple program by imaginationhunt blogs
Simple program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code the program.

Practical Implementation:

using System;

namespace patternProblem.Simple_program
{
    class Simple9   //Calculator program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.Write("Enter first number: ");
                int firstNumber = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter second number: ");
                int secondNumber = Convert.ToInt32(Console.ReadLine());
                Console.Write("Choose an operator type from +, -, *, /, %: ");
                char operatorSymbol = Convert.ToChar(Console.ReadLine());
               
                Console.WriteLine();

                Console.WriteLine("-----Output-----");
                Console.WriteLine();
                switch (operatorSymbol)
                {
                    case '+':
                        Console.WriteLine("{0} + {1} = {2}", firstNumber, secondNumber, firstNumber + secondNumber);
                        break;
                    case '-':
                        Console.WriteLine("{0} - {1} = {2}", firstNumber, secondNumber, firstNumber - secondNumber);
                        break;
                    case '*':
                        Console.WriteLine("{0} * {1} = {2}", firstNumber, secondNumber, firstNumber * secondNumber);
                        break;
                    case '/':
                        Console.WriteLine("{0} / {1} = {2}", firstNumber, secondNumber, (double)(firstNumber / secondNumber));
                        break;
                    case '%':
                        Console.WriteLine("{0} % {1} = {2}", firstNumber, secondNumber, firstNumber % secondNumber);
                        break;
                    default:
                        Console.WriteLine("Invalid ! operation");
                        break;
                }

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error! : " + ex.Message);
            }
        }
    }
}

Output:
The input numbers are 5 and 6. The program will do calculation based on the input operator. The output is shown below:

Enter first number: 5
Enter second number: 6
Choose an operator type from +, -, *, /, %: *

5 * 6 = 30
Press any key to continue . . .


For any query, comment us below.

Skip to Main Table Simple program

Previous - Simple program #9


Click imagination hunt to read latest blogs.


Keep learning and sharing...
Read More »

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...