C# Operator Example

In this chapter you will learn:
  • The main objective of this chapter is to explain you in details about how to use C# operators in a program.
Qu 1. Write a program to check whether input character is vowel or not.
Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace operator_example_1
{
    class Program
    {
        static void Main(string[] args)
        {
            char ch;

            Console.Write("Enter a character: \t");
            ch = Convert.ToChar(Console.ReadLine());

            if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U')
            {
                Console.WriteLine("\n\n{0} is vowel", ch);
            }
            else
            {
                Console.WriteLine("\n\n{0} is not vowel", ch);
            }
            Console.ReadLine();
        }
    }
}

Enter a character :     E

E is vowel __
 
Qu 2. Calculate area of Rectangle
Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace operator_example_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int height, width, area;

            Console.Write("Enter height:\t");
            height = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter width:\t");
            width = Convert.ToInt32(Console.ReadLine());

            area = height * width;

            Console.WriteLine("\nArea of Rectangle is {0}", area);
            Console.ReadLine();
        }
    }
}

Enter height :   5
Enter width :    6
Area of Rectangle is 30
__

Summary

In this chapter, you saw some programming examples of C# operators. In next chapter, there are some programming exercises are given. It is recommended you to do all the Exercises honestly.

More Articles

 

Share your thought



PLEASE DISABLE ADBLOCKER AND SUPPORT US!

Please support us by enabling ads on this page. Refresh

YOU DON'T LIKE ADS, WE ALSO DON'T LIKE ADS!
 
But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.