C# Program that Subtracts two user defined numbers

C# Program that Subtracts two user-defined numbers

C# Program that Subtracts two user defined numbers

Object:

Make a class for subtraction, define a method sub, which subtracts two user-defined numbers. Call it in the main program. C# Projects with Source Code

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lab1b
{
class subtraction
{
public void sub(int a, int b)
{
Console.WriteLine(“Value of a is : ” +(a));
Console.WriteLine(“Value of b is : ” + (b));
Console.WriteLine(“\nSubtraction of Two Numbers is = ” + (a – b));
}
}
class Program
{
static void Main(string[] args)
{
subtraction obj = new subtraction();
obj.sub(5, 3);
Console.ReadKey();
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lab1b
{
    class subtraction
    {
        public void sub(int a, int b)
        {
            Console.WriteLine("Value of a is : " +(a));
            Console.WriteLine("Value of b is : " + (b));
            Console.WriteLine("\nSubtraction of Two Numbers is = " + (a - b));
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            subtraction obj = new subtraction();
            obj.sub(5, 3);
            Console.ReadKey();
        }
    }
}

Output:

C# Program that Subtracts two user defined numbers

Another Program: C# Program Calculating the Area of a Rectangle

C++ projects for beginners with source code

8 thoughts on “C# Program that Subtracts two user defined numbers”

  1. Pingback: How to Input any Number in C#

  2. Pingback: C# program to count vowels in a string

  3. Pingback: Write a C# program that reads two arrays and checks whether they are equal.

  4. Pingback: Develop a C# app that will determine the gross pay for each of three employees

  5. Pingback: Write a C# program to create a static function factorial and calculate factorial of the number.

  6. Pingback: C# Program Create a class student with a data members name and calculate marks and percentage.

  7. Pingback: Implement bubble sort in C# the value of array given by the users

  8. Pingback: Top 20 C# programs examples in 2021

Leave a Comment

Your email address will not be published. Required fields are marked *