Write a C# program to add two numbers without using ‘+’ operator.

Write a C# program to add two numbers without using ‘+’ operator.

Last updated:11/24/2021 10:24:23 PM

1 Answers

Ashutosh Kumar Verma
Ashutosh Kumar Verma

Generally ‘+’ operator is used to add two numbers but in the following C# program there are add two numbers without using ‘+’ operator.

Program:

using System;

public class Program
{
 public static void Main()
 {
  int a=6,b=15;
  Console.Write('Sum of '+a+' and '+b+' is : ');
  while(b!=0)
  {
   a++;
   b--;
  }
  Console.WriteLine(a);
 }
}
Output:    Sum of 6 and 15 is : 21

Input number in runtime by user.

Program:

using System;
public class Program
{
 public static void Main()
 {
  int a,b;
  Console.Write('Enter the first number ');
  a=int.Parse(Console.ReadLine());
  Console.Write('Enter the second number ');
  b=int.Parse(Console.ReadLine());
  Console.Write('Sum of '+a+' and '+b+' is : ');
  while(b!=0)
  {
   a++;
   b--;
  }
  Console.WriteLine(a);
 }
}
Output:

Enter the first number 14
Enter the second number 210
Sum of 14 and 210 is : 224


Answer