finds the sum, product, min and max of two numbers - CSharp Language Basics

CSharp examples for Language Basics:int

Description

finds the sum, product, min and max of two numbers

Demo Code

using System;/*from   w ww  .  j  av  a 2s. c  o  m*/
public class SimpleCalculator
{
   public static void Main()
   {
      int x;
      int y;
      Console.Write("Enter first number: ");
      x = Convert.ToInt32(Console.ReadLine());
      Console.Write("Enter second number: ");
      y = Convert.ToInt32(Console.ReadLine());
      Console.WriteLine("The sum is: " + Sum(x, y));
      Console.WriteLine("The product is: " + Product(x, y));
      Console.WriteLine("The maximum number is: " + Math.Max(x, y));
      Console.WriteLine("The minimum number is: " + Math.Min(x, y));
   }
   // Sum calculates the sum of two int's
   public static int Sum(int a, int b)
   {
      int sumTotal;
      sumTotal = a + b;
      return sumTotal;
   }
   // Product calculates the product of two int's
   public static int Product(int a, int b)
   {
      int productTotal;
      productTotal = a * b;
      return productTotal;
   }
}

Result


Related Tutorials