Factorial program in C#


Factorial program in C# is given below.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
     

            for (int i = 1; i < 10; i++)
            {
                int f = 1;
                for (int j = i; j >= 1; j--)
                {
                    f *= j;
                }
                label1.Text += i+"! = " + f + '\n';
            }
           
        }

        private void label1_Click(object sender, EventArgs e)
        {
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

Maximum number program in C#

Finding Maximum Number program in C# program is given in the video below.




Finding maximum number in C# by MuhammadRehanQadri


I hope this tutorial of "finding maximum number program in C#" helped you. I'd be glad to hear from you.

Compound Interest program in C#


//Calculating Compound Interest program in C#

using System;
using System.Windows.Forms;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal amount, principal = (decimal)1000.00;
            double rate = .05;
            string output;
            output = "Year\tAmount on Deposit\n";

            for (int year = 1; year <= 10; year++)
            {
                amount = principal * (decimal)Math.Pow(1.0 + rate, year);
                output += year + "\t" + amount + "\n";
            }
            MessageBox.Show(output,"Calculating Compound Interest in C#",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }
    }
}

How to add Reference in C#

How to add Reference in C# is explained through the following video.



How to Add reference in C# by MuhammadRehanQadri

I hope this tutorial of "How to Add reference in C#" helped you. I'd be glad to hear from you.

While loop in C#


//While loop in C#

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 1;
            while (x != 6)
            {
                Console.Write(x + " ");
                x++;
            }
        }
    }
}

For loop in C#


//For Loop in C#

using System;
using System.Windows.Forms;//To use MessageBox.Show

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 3; i++)
            {
                MessageBox.Show("Hi  "+i); //Displays the message in box. Works like Console.Write("Hi  "+i) (i.e. print command).
            }
        }
    }
}

if statement in C#


// If statement in C#

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(3 < 4 ? "HI" : "BY");
        }
    }
}