C# program to demonstrate an example of assignment operators

Example:

    Input:
    int a = 10;
    int b = 3;

    //operations & outputs
    a = 100;    //value of a will be 100
    a += b;     //value of a will be 103
    a -= b;     //value of a will be 100
    a *= b;     //value of a will be 300
    a /= b;     //value of a will be 100
    a %= b;     //value of a will be 1

C# code to demonstrate example of assignment operators:

// C# program to demonstrate example of 
// assignment operators 
using System;
using System.IO;
using System.Text;

namespace JustTechReview
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            int a = 10;
            int b = 3;

            Console.WriteLine("a: {0}", a);
            a = 100; //assigment
            Console.WriteLine("a: {0}", a);
            a += b;
            Console.WriteLine("a: {0}", a);
            a -= b;
            Console.WriteLine("a: {0}", a);
            a *= b;
            Console.WriteLine("a: {0}", a);
            a /= b;
            Console.WriteLine("a: {0}", a);
            a %= b;
            Console.WriteLine("a: {0}", a);


            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}

Output:

a: 10
a: 100
a: 103
a: 100
a: 300
a: 100
a: 1

Leave a Comment

error: Alert: Content is protected!!