CSharp - Write program to Use Incrementing and Decrementing Operators

Requirements

You'll use increment operator (++) and the decrement operator (--).

  • Read user input
  • Store the user input into a variable
  • Use the Incrementing and Decrementing Operators:++ --

Hint

Here is an illustration of how to use Incrementing and Decrementing Operators.

number++; // same as number = number + 1; 
number--; // same as number = number - 1; 

Demo

using System;
class Program/*  w  w w  .j a  v  a  2 s.  c o  m*/
{
    static void Main(string[] args)
    {
        // Input 
        Console.Write("Enter a number: ");
        string input = Console.ReadLine();
        int number = Convert.ToInt32(input);

        // Increasing by 1 using INCREMENT OPERATOR 
        number++; // same as number = number + 1; 
        Console.WriteLine("Increased by 1: " + number);

        // Decreasing by 1 using DECREMENT OPERATOR 
        number--; // same as number = number - 1; 
        Console.WriteLine("Back again: " + number);
    }
}

Result