Friday 4 July 2014

Write C# code to prompt a user to enter an integer value.

The value is stored in a variable called a. Then the program will show the output as seen below:
The value of a is 10.
................................
The value of ++a is 11.
The value of a is 11.
The value of a++ is 11.
The value of a is 12.
The value of --a is 11.
The value of a is 11.
The value of a-- is 11.
The value of a is 10.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Csharp_exercises
{
class Program
{
static void Main(string[] args)
{


int a;
int b;

Console.Write("Enter a value:");


a=int.Parse(Console.ReadLine()) ;

Console.WriteLine("The value of a is {0}.",a);

b=++a;

Console.WriteLine("The value of ++a is {0}.",b);

Console.WriteLine("The value of a is {0}.",a);
b = a++;

Console.WriteLine("The value of a++ is {0}.", b);
Console.WriteLine("The value of a is {0}.", a);

b=--a;

Console.WriteLine("The value of --a is {0}.", b);
Console.WriteLine("The value of a is {0}.", a);


b=a--;

Console.WriteLine("The value of a-- is {0}.", b);
Console.WriteLine("The value of a is {0}.", a);


Console.ReadLine();
 
    }
  }
}
 



No comments:

Post a Comment