Sunday, 11 September 2016

C# Program to Check Whether the Given Number is a Prime number or not.

This C# Program Checks Whether the Given Number is a Prime number or not.
It will ask a user to enter a number and check whether it is prime or not.

using System;

namespace CsharpProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter a Number : ");

            int _Number;

            _Number = Convert.ToInt32(Console.ReadLine());

            int _Flag;

            _Flag = 0;

            for (int i = 1; i <= _Number; i++)
            {
                if (_Number % i == 0)
                {
                    _Flag++;
                }
            }

            if (_Flag == 2)
            {
                Console.WriteLine("Entered Number is a Prime Number.");
            }
            else
            {
                Console.WriteLine("Not a Prime Number");
            }
            Console.ReadKey();
        }
    }
}


Mathematical Calculation in C# using Math Class.

Math class can be use for maths related calculation.

some of useful math class methods are illustrated with example.

- Math.BigMul() : use for getting multiplication of two number.
- Math.Ceiling() : use for getting number that is greater than or equal to the specified double-precision floating-point number.
- Math.Floor() : use for getting integer that is less than or equal to the specified double-precision floating-point number.
- Math.Sin() : Returns the sine of the specified angle.
- Math.Cos() : Returns the cosine of the specified angle.
- Math.Tan() : Returns the tangent of the specified angle.
- Math.Sqrt() : Returns the square root of a specified number.
- Math.Max() : Returns the larger of two number.
- Math.Min() : Returns the smaller of two number.

using System;

namespace CsharpProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            double Multiplication, CeilingValue, FloorValue;

            Multiplication = Math.BigMul(7823, 2345);

            CeilingValue = Math.Ceiling(76.43);

            FloorValue = Math.Floor(76.43);

            Console.WriteLine("7823 * 2345 = " + Multiplication);

            Console.WriteLine("Ceiling value of 76.43 is " + CeilingValue);

            Console.WriteLine("Floor value of 76.43 is " + FloorValue);

            double sin_Result, cos_Result, tan_Result;

            sin_Result = Math.Sin(30);
            cos_Result = Math.Cos(30);
            tan_Result = Math.Tan(30);

            Console.WriteLine("Sin of angle 30 is " + sin_Result);
            Console.WriteLine("Cos of angle 30 is " + cos_Result);
            Console.WriteLine("Tan of angle 30 is " + tan_Result);

            double SquareRoot;

            SquareRoot = Math.Sqrt(144);

            Console.WriteLine("Square Root of 144 is " + SquareRoot);

            int MaxValue, MinValue;

            MaxValue = Math.Max(34, 76);
            MinValue = Math.Min(34, 76);

            Console.WriteLine("Maximum of 34 and 76 is " + MaxValue);
            Console.WriteLine("Minimum of 34 and 76 is " + MinValue);

            Console.ReadKey();
        }
    }
}

Hello World in C#.Net

Hello World Program in C#.Net

using System;

namespace CsharpProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
    }
}


Here Console.WriteLine() is use to display message to console screen.
Console.ReadKey(); is used to retain console screen , it will wait for user to press any key.


c# program which ask for your name and write it back with Greet.

using System;

namespace CsharpProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            string Name;
            Console.WriteLine("Please enter your name!");
            Name = Console.ReadLine();

            Console.WriteLine("Hello, Your name is " + Name);
            Console.ReadKey();
        }
    }
}

Console.ReadLine() is use to read message entered by user.

Friday, 9 September 2016

you can call javascript function from code behind using ScriptManager.

Declare required function in javascript,

<script type="text/javascript" language="javascript">
    function GetMessage() {
        alert("hello!")
    }
</script>

Write below line where you want to call Javascript function,
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "smMain", "GetMessage();", true);