Basic C# Simple Programs for Interview

Hi Friends this time I am sharing you a very simple basic programs that generally asked at the time of interview. I used to ask it sometimes very simple programs. We know that we can make it out that program but in interview time if you know how to do that then you can make it out very easily and make a face that you are thinking about it. But you know already. and write it after some moments. So just take a look before the interview.

Program 1: Return Vowel of Not. Solution.

  1. public bool CheckVowel(object sender,KeyEventArgs e)   
  2. {   
  3.    if(e.KeyCode ==Keys.A||e.KeyCode ==Keys.E||e.KeyCode ==Keys.I||e.KeyCode ==Keys.O||e.KeyCode ==Keys.U)   
  4.    {   
  5.       return true;   
  6.    }   
  7.    else   
  8.    return false;   
  9. }  
Program 2: Even or Odd Solution.
  1. public string EvenOrOdd( int Num)   
  2. {   
  3.    if(num%2 ==0)   
  4.    retrun "evenNumber";   
  5.    else   
  6.    return "OddNumber"   
  7. }   
Program 3: Prime Number Solution.
  1. public string PrimeOrNot(int num)   
  2. {   
  3.    int i = 0;   
  4.    for (i = 3; i < num; i++)   
  5.    {   
  6.       if (num % i == 0)   
  7.       {   
  8.          Console.WriteLine("{0} is not a prime number", num);   
  9.          break;   
  10.       }   
  11.    }   
  12.    if (i == num)   
  13.    {   
  14.       Console.Writeline("{0} is a prime Number", num);   
  15.    }   
  16. }   
Program 4: Fibonacci Series Solution.
  1. public void FibonacciSeries(int number)   
  2. {   
  3.    int f_0 = 0;   
  4.    int f_1 = 1;   
  5.    int sum;   
  6.    Console.Write("{0} {1} ", f_0, f_1);   
  7.    for (int i = 2; i < number; i++)   
  8.    {   
  9.       sum = f_0 + f_1;   
  10.       f_0 = f_1;   
  11.       f_1 = sum;   
  12.       int value = f_0 + f_1;   
  13.       Console.Write("{0} ", value);   
  14.    }   
  15. }   
Program 5: Factorial Solution.
  1. public int Factorial(int number)   
  2. {   
  3.    int value = 1;   
  4.    for (int i = 1; i <= number; i++)   
  5.    {   
  6.       value = value * i;   
  7.    }   
  8.    return value;   
  9. }   
Program 6: Permutation (nPr) Solution.

Reference Solution 5
  1. public double Permutation(int n, int r)   
  2. {   
  3.    double nPr = Factorial(n) / Factorial(n - r);   
  4.    return nPr;   
  5. }   
Program 7: Combination (nCr) Solution.

Reference Solution 5
  1. public double Combination(int n , int r)   
  2. {   
  3.    double nCr = Factorial(n)/Factorial(r)*(Factorial(n-r);   
  4.    return nCr;   
  5. }   
Program 8: Add two numbers without using the plus operator Solution.
  1. public int Add (int x , int y )   
  2. {   
  3.    return x-(-y);   
  4. }   
Program 9: Multiply two numbers without usering * operator Solution.

  1. public int MulWithOutStarOperator( int x ,int y)   
  2. {   
  3.    for(int z= 1 ; z<=y ; z++)   
  4.    {   
  5.       int value = value +x;   
  6.    }   
  7.    return value;   
  8. }   

 

Ebook Download
View all
FileInfo in C#
Read by 9.7k people
Download Now!
Learn
View all