C# program to enter two numbers and find their sum
ADVERTISEMENTS
C# program to enter two numbers and find their sum. In this program, you will learn how to find the sum of two numbers.
C# program to find the sum of two integer values:
// C# program to enter two numbers and find their sum
using System;
public class W3CW {
// @It's the driver function
static public void Main (string[] args) {
Console.WriteLine("Enter two integer values::");
int p = Convert.ToInt32(Console.ReadLine());
int q = Convert.ToInt32(Console.ReadLine());
// calculating sum
int r = p + q;
Console.WriteLine("\nResult:: " + p + " + " + q + " = " + r);
}
}
C# program to find the sum of two integers with minimum values:
// C# program to find the sum of two integers with minimum values
using System;
public class W3CW {
// @It's the driver function
static public void Main (string[] args) {
Console.WriteLine("Enter two integer values::");
int p = Convert.ToInt32(Console.ReadLine());
int q = Convert.ToInt32(Console.ReadLine());
Console.Write("\nResult:: " + p + " + " + q + " = ");
// calculating sum
p = p + q;
Console.WriteLine(p);
}
}
Output:
Enter two integer values::
5
7
Result:: 5 + 7 = 12
C# program to find the sum of two float values:
// C# program to find the sum of two float values
using System;
public class W3CW {
// @It's the driver function
static public void Main (string[] args) {
Console.WriteLine("Enter two float values::");
float p = float.Parse(Console.ReadLine());
float q = float.Parse(Console.ReadLine());
Console.Write("\nResult:: " + p + " + " + q + " = ");
// calculating sum
p = p + q;
Console.WriteLine(p);
}
}
Output:
Enter two float values::
5.23
7.29
Result:: 5.23 + 7.29 = 12.52