Friday, 1 September 2017

c# programming tutorial to Find maximum out of 3 numbers

Find maximum out of 3 numbers

using System;
class Program
    {
        static void Main(string[] args)
        {
int a, b,c;
Console.WriteLine("Number 1:");
a = Convert.ToInt32(Console.ReadLine());            
Console.WriteLine("Number 2:");            
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Number 3:");
c = Convert.ToInt32(Console.ReadLine());  
            if (a > b && a > c)
            {
                Console.WriteLine("a is max");
            }
            else if (b > a && b > c)
            {
                Console.WriteLine("b is max");
            }
            else
            {
                Console.WriteLine("c is max");
            }
        }

    }  

Output


c# programming tutorial to implement a Sum of Two number

Simple Program example to sum of two

Program

using System;
class Program
    {
        static void Main(string[] args)
        {
             int a, b, c;
             Console.WriteLine("Number 1:");            
 a = Convert.ToInt32(Console.ReadLine());            
             Console.WriteLine("Number 2:");
 b  = Convert.ToInt32(Console.ReadLine());
 c = a + b;
            Console.WriteLine("Addition: {0}", c);
        }

   }

Output


c# tutorial programming | create calculator using switch case

Create Calculator Using Switch Case

Program

using System;
class Program
{
static void Main(string[] args)
{
int a, b, c;
Console.WriteLine("Number 1:");            
a = Convert.ToInt32(Console.ReadLine());          
Console.WriteLine("Number 2:");            
b = Convert.ToInt32(Console.ReadLine());           
Console.WriteLine("1. Add  2. Sub  3. Mul  4. div");            
int ch = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();            
switch (ch)
{
case1:
c = a + b;
Console.WriteLine("Addtion : {0}", c);
break;
case2:
c = a - b;
Console.WriteLine("Subtraction: {0}",c);
break;
case 3:
c = a * b;
Console.WriteLine("Multiplication: {0}",c);
break;
case 4:
c = a / b;
Console.WriteLine("Division: {0}",c);
break;
default:
Console.WriteLine("Invalid Choice");
break;
            }
        }
  }  

Output


c# programming tutorial to implement a Swap 2 Numbers Using Function

Program example to sum of two use to function C# Programming

Program

class Program
 {
static void swap(ref int x,ref int y)
        {
             int z = x;           
             x = y;
             y = z;
        }

static void Main(string[] args)
        {
             int a, b;
            Console.WriteLine("Number 1:");
             a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Number 2:");
            b = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("After Swapping");
             swap(ref a,ref b);
            Console.WriteLine("Number 1: {0} , Number 2: {1}", a, b);
        }

    }  

Output


c# Program to check whether a number is palindrome or not

Simple C# Program example to check Given number is palindrome or not?

Program

using System;     
class Program
    {
        static void Main(string[] args)
        {
            int num, n, s = 0,a;
            Console.WriteLine("Enter the Number:");
            num = Convert.ToInt32(Console.ReadLine());             
            a = num;
            while (num != 0)
            {
                n = num % 10;               
 s = n + (s * 10);
                num = num / 10;
            }
            Console.WriteLine("Reverse Number : {0}", s);           
 if (s == a)
            {
                Console.WriteLine("Palindrome");
            }            
else
            {
                Console.WriteLine("Not Palindrome");
            }
        }

    }  

Output


c# Program tutorial to generate Fibonacci series up to N Numbers

create a simple c# program to generate Fibonacci series up to N Numbers

Program

using System;
class Program
    {
        static void Main(string[] args)
        {
               int a = 0, b = 1, c = 1, n;
               Console.WriteLine("Number:");            
n = Convert.ToInt32(Console.ReadLine());
               Console.WriteLine(a);            
Console.WriteLine(b);
               while((a+b)<=n)
               {
                 c = a + b;
                Console.WriteLine(c);
                 a = b;
                 b=c;
            }
        }

Output


C# tutorial programming | C# program to generate following output

create a simple c# program to generate following output

1

22

333

4444

55555

Program

using System; 
class Program
    {
        static void Main(string[] args)
        {
            int i, j;
            for (i = 1; i <= 5; i++)
            {
                for (j = 1; j <= i; j++)
                {
                    Console.Write(i);
                }
                Console.WriteLine();
            }
        }   

 } 

Output


C# tutorial programming | C# program to generate following output

C# program to generate following output

1

12

123

1234

12345

Program

using System;
class Program
    {
        static void Main(string[] args)
        {
            int i, j;           
 for (i = 1; i <= 5; i++)
            {
                for (j = 1; j <= i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
        }   

 } 

Output


C# tutorial programming | C# program to generate following output

create a simple c# program to generate following output

Program

using System;
class Program
    {
        static void Main(string[] args)
        {
            int i, j;
            for (i = 1; i <= 5; i++)
            {
                for (j = 1; j <= i; j++)
                { 
                    if (j % 2 == 0)
                    {
                        Console.Write("0");
                    }
                     else
                    {
                        Console.Write("1");
                    }
                }
                Console.WriteLine();
            }
        }

     } 

Output


C# programming tutorial to find the summation of all the odd and all the even numbers between two number

create a simple c# program to generate sum of odd and even number betwwen two number

Program

using System;
class Program
    {
        static void Main(string[] args)
        {
            int e = 0, o = 0, a = 200, b = 800;
            while (a <= b)
            {
                if (a % 2 == 0)
                {
                    e = e + a;
                }
                Else
                 {
                    o = o + a;
                }
                a++;
            }
            Console.WriteLine("Even Sum :{0}", e);
            Console.WriteLine("Odd Sum :{0}", o);
        }

     } 

Output


C# programming to demonstrate use of pass by reference

C# program example to use of pass by reference in C# program

Program

using System;
class Program
    {
        static void Main(string[] args)
        {
            int a = 5, b = 6;
             swap(ref a, ref b);
        }
        public static void swap(ref int x, ref int y)
        {
            int z;
            z = x;
             x = y;
             y = z;
            Console.WriteLine("a: {0}  b:{1}", x, y);
        }

     } 

Output


C# programming tutorial to implement demonstrate output parameter

C# program example to use of output parameter in C# 

program

using System;
class Program
    {
        static void mult(int x,int y, out int z)
        {
             z = x * y;
        }
        static void Main(string[] args)
        {
            int m, n, o;
            Console.WriteLine("Enter the Number1:");
             n = Convert.ToInt32(Console.ReadLine());
             Console.WriteLine("Enter the Number2:");
             o = Convert.ToInt32(Console.ReadLine());
            mult(n, o, out m);
            Console.WriteLine("The Multiplication : {0}", m);
        }

    } 

Output


C# program example to demonstrate use of Constructor

C# program to demonstrate use of Constructor

Program

using System;
class Program
    {
        static void Main(string[] args)
        {
            demo s = new demo(10, 5);
            int a = s.area();
            Console.WriteLine("Output:{0}", a);
        }
    }
    class demo
    {
        int l, w;
        public demo(int x, int y)
        {
             l = x;
             w = y;
         }
        public int area()
        {
            return l * w;
        }
     }

Output


C# program example to demonstrate to use of Polymorphism

C# program example to use of Polymorphism in C# program

Program

using System;    
class Program
    {
        static void Main(string[] args)
        {
             add(10);
             add(10, 20);
        }
        public static void add(int x, int y)
        {
            int z = x + y;
            Console.WriteLine("Output1:{0}", z);
        }
        public static void add(int x)
        {
            int y = x + x;
            Console.WriteLine("Output2:{0}", y);
        }

Output


C# programming tutorial to implement the use of Multilevel Inheritance

C# program example to use of Multilevel Inheritance in C# program

Program

using System;
    class A     {
        public void print()
        {
            Console.WriteLine("Class A");
        }
     }
      class B : A
    {
        public void print1()
        {
            Console.WriteLine("Class B");
        }
    }
     class C : B
    {
        public void print2()
        {
            Console.WriteLine("Class C");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            C b = new C();
             b.print();
            b.print1();
            b.print2();
        }

    } 

Output


C# program to implement the use of implement Interface

C# program example to use of implement Interface in C# program

Program

using System;
interface area
    {
        double calc(double x);
    }
     class B : area
    {
        public double calc(double x)
        {
            return x * x;
        }
     }
     class C : B
    {
        public double calc(double x)
        {
            return Math.PI * x * x;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            C c = new C();
             double d= c.calc(5.5);
             Console.WriteLine("Area 1: {0}", d);

            area a;
            B b = new B();
             a = b as area;
             double r = a.calc(6.5);
             Console.WriteLine("Area 2: {0}", r);
            
        }

     } 

Output


C# program to implement the use of Delegates

C# program example to use of implement Delegates in C# program

Program

using System;
delegate int calc(int x,int y);
class oper    {
       public static int add(int x, int y)
       {
           return x + y;
       }
       public static int sub(int x, int y)
       {
            return x - y;
       }
   }
    class Program
    {
        static void Main(string[] args)
        {
            calc c1 = new calc(oper.add);
             calc c2 = new calc(oper.sub);

            int a = c1(50, 40);
            int b = c2(30, 10);

            Console.WriteLine("Add: {0}", a);
            Console.WriteLine("Sub: {0}", b);
        }

    } 

Output


C# program example to implement the use of Properties

C# program example to use of Properties in C# program

Program

using System;
class Number
    {
        int num;
        public int anum // Property Declaration
        {
             Get
              {


                return num;
            }
             set
            {
                num = value;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Number n = new Number();
            int b;
            Console.WriteLine("Enter Number: ");
             b = Convert.ToInt32(Console.ReadLine());
             n.anum = b; // Invoke Set Property
             int a = n.anum; // Invoke Get Property
             Console.WriteLine("Answer: {0}", a);
        }

     } 

Output


C# programming tutorial to implement the use of Indexers

C# tutorial programming | C# program to implement the use of Indexers

Program

using System; class Number
    {
        int[] a = new int[4];  // Array Declaration
        public int this[int index] // Indexer Declaration
        {
            get   // Getter Method (Output Defining)
            {
                return a[index];
            }
            set   // Setter Method (Input and Assigning Values)
            {
                a[index] = value;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Number n = new Number();             // Array and Indexer Instantiation
            n[0] = 1;
             n[1] = 2;
             n[2] = 3;
             n[3] = 4;
            Console.WriteLine("The Index Values are:");
            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine("Value at Index[{0}] : {1}", i, n[i]);
            }
        }

    }

Output


PHP | List of All Type OF Comment in PHP Program - W3Tricks

List of All Type OF Comment in PHP Program


Program

<?php

// This is a single-line comment

# This is also a single-line comment

/* This is a multiple-lines

comment block that spans

over multiple lines  */

// You can also use comments to leave out parts of a code line $x = 5 /* + 15 */ + 5; echo $x;

?> 

PHP | Variable in PHP | Rules for define PHP variables - W3Tricks

Variable in PHP | Rules for define PHP variables


What is Variable and what it Work?

  • Variables are "containers" for storing( Hold ) information( Data ).

Rules for define PHP variables

  • A variable name must start with a letter ( A - Z and a - z ) or the underscore Symbol ( _ ).
  • A variable name cannot start with a number ( 1 to 0).
  • A variable name can only contain alphanumeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive ($Data and $data are two different variables).

Program

<?php

$1data; // not valid start with number
$123;   // not valid start with number
$*data //  not valid start with Symbol

$data; // it is valid
$_data; // it is valid
$_123; // it is valid


$data;
$Data;

/* both are different Variables */

?>

Note:

  • When you assign a text value to a variable ( $string = "IT is String"; ) put quotes around the value.
  • Unlike other programming languages PHP is loosely typed language, PHP has no command for declaring a variable.
  • It is created the moment you first assign a value to it.
  • 1. $int = 132; // It is integer 2. $str = "String"; // It is String

PHP | Simple PHP Variables Scope in Program - W3Tricks

PHP Variables Scope in Program


Variables Scope

  • Variables can be declared anywhere in the PHP program.
  • Main Two Type of variable scopes
  • 1. Global. 2. Local.

What is Global variable scopes?

  • A variable declared outside of any function and block has a GLOBAL SCOPE and can only be accessed outside a function and block.

What is Local variable scopes?

  • A variable declared within any function and block has a LOCAL SCOPE and can only be accessed within that function and block.

Program

<?php

$data = 5; // Global Variable.

function info(){
$data = 10; // Local Variable.
echo "IT IS Local Variable". $data . "<br/>";
}
info();
echo "<br />IT IS Global Variable". $data;

?>

Global keyword

  • Use Global keyword in Program and what is a use of global function?
  • The global keyword is used to access a global variable from within a function and block.

Program

<?php

$A = 5; // Global Variable.

function info(){
$B = 10; // Local Variable.
global $A;
$sum = $A + $B;
echo "Output Sum :". $sum . "<br/>";
}
info();

?>

Output