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:
Another Program: C# Program Calculating the Area of a Rectangle
C++ projects for beginners with source code
Pingback: How to Input any Number in C#
Pingback: C# program to count vowels in a string
Pingback: Write a C# program that reads two arrays and checks whether they are equal.
Pingback: Develop a C# app that will determine the gross pay for each of three employees
Pingback: Write a C# program to create a static function factorial and calculate factorial of the number.
Pingback: C# Program Create a class student with a data members name and calculate marks and percentage.
Pingback: Implement bubble sort in C# the value of array given by the users
Pingback: Top 20 C# programs examples in 2021