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();
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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
7 Responses
[…] Another Program: C# Program that Subtracts two user-defined numbers […]
[…] Another C# Program: C# Program that Subtracts two user-defined numbers […]
[…] Another C# Program: C# Program that Subtracts two user-defined numbers […]
[…] Another C# Program: C# Program that Subtracts two user-defined numbers […]
[…] Another C# Program: C# Program that Subtracts two user-defined numbers […]
[…] Another Program: C# Program that Subtracts two user-defined numbers […]
[…] Another C# Program: C# Program that Subtracts two user-defined numbers […]