Sunday, December 28, 2014

ARITHMETIC AND LOGICAL OPERATORS

8:21 PM - By azeheruddin khan 0

Program to Show the use of all Arithmetic Operators (increment, decrement, addition, subtraction, multiplication, division, modulus)

using System;
namespace ArithmeticExample
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d, e, f;
            Console.Write("enter the value of a:");
            a = Convert.ToInt32(Console.ReadLine());
            Console.Write("enter the value of b:");
            b = Convert.ToInt32(Console.ReadLine());
            Console.Write("enter the value of c:");
            c = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            d = a + b;
            Console.WriteLine("{0}+{1}={2}", a, b, d);
            d = b - c;
            Console.WriteLine("{0}-{1}={2}", b, c, d);
            d = a * b * c;
            Console.WriteLine("{0}*{1}*{2}={3}", a, b, c, d);
            d = (a * b * c) / d;
            Console.WriteLine("{0}/{0}={1}", a * b * c, d, d);
            d = (a * b * c) % d;
            Console.WriteLine("{0}/{0}={1}", a * b * c, d, d);
            Console.WriteLine();
            e = d++;
            Console.WriteLine("After post-increment of d");
            Console.WriteLine("the value of e is " + e);
            Console.WriteLine("the value of d is " + d);
            Console.WriteLine();
            e = ++d;
            Console.WriteLine("After pre-increment of d");
            Console.WriteLine("the value of e is " + e);
            Console.WriteLine("the value of d is " + d);
            Console.WriteLine();
            d = 0;
            f = d--;
            Console.WriteLine("after post-decrement of d");
            Console.WriteLine("the value of f is " + f);
            Console.WriteLine("the value of d is " + d);
            Console.WriteLine();
            Console.WriteLine("after pre-decrement of d");
            f = --d;
            Console.WriteLine("the value of f is " + f);
            Console.WriteLine("the value of d is " + d);
            Console.ReadLine();

        }
    }
}


Output:


Program to show the use of Logical operators like AND (&&), OR (||) and NOT (!) and relational operators like greater than(>), equal to operator (==) and not equal to (!=).
using System;

namespace ArithmeticExample
{
    class Program
    {

        static void Main(string[] args)
        {
            int a, b, c;
            Console.Write("enter the value of a:");
            a = Convert.ToInt32(Console.ReadLine());
            Console.Write("enter the value of b:");
            b = Convert.ToInt32(Console.ReadLine());
            Console.Write("enter the value of c:");
            c = Convert.ToInt32(Console.ReadLine());
            if (a > b && a > c)
            {
                Console.WriteLine("the greatest number is {0}", a);
            }
            else if (b > c && b > a)
            {
                Console.WriteLine("the greatest number is {0}", b);
            }
            else Console.WriteLine("the greatest number is " + c);
            if (a == b || b == c || c == a)
            {
                Console.WriteLine("above given two numbers are same");
            }
            if (a != b && a != c && b != c)
            {
                Console.WriteLine("all the three numbers are unique");
            }

            Console.ReadLine();


        }
}
}

Output:





About the Author

I am Azeheruddin Khan having more than 6 year experience in c#, Asp.net and ms sql.My work comprise of medium and enterprise level projects using asp.net and other Microsoft .net technologies. Please feel free to contact me for any queries via posting comments on my blog,i will try to reply as early as possible. Follow me @fresher2programmer
View all posts by admin →

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

adsense

© 2014 Fresher2Programmer. WP Theme-junkie converted by Bloggertheme9
Powered by Blogger.
back to top