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