Factorial is a positive number which is the product of all number less than or equal to that positive number. For example: 0! = 1 1! = 1 2! = 2 * 1! = 2 3! = 3 * 2! = 6 … n! = n * (n – 1)! Here is the sample code
Category: Code Samples
Properties a short explanation using C#
What Are Properties? Properties are methods that protect access to class members. Properties are class members that provide access to elements of an object or class. Protect access to the state of object. It likes fields, but they operate much like methods. The get and set statements are called accessors. Fields can’t be used in
Static Constructor and C# implementation
Static Constructor Instance constructors are used to initialize an object Static constructors are used to initialize a class Will only ever be executed once Run before the first object of that type is created. Have no parameter Do not take an access modifier May co-exist with a class constructor Syntax: class Lion { static Lion()
Love Calculator using C#
Love Calculator public class LoveCalculator { public string GetResults(string name1, string name2) { return GetCount(name1, name2); } private string GetCount(string firstName, string secondName) { try { string first = firstName.ToUpper(); int firstlength = firstName.Length; string second = secondName.ToUpper(); int secondlength = secondName.Length; int LoveCount = 0; for (int Count = 0; Count < firstlength; Count++)
How to remove special character from Unicode string
Here is the sample code to remove special character from Unicode string. Sample Input: SG@%@sgs th? g#%@^@#$ chào^#^$#!abc35| _ sgs _35 hello world không gsg Sample Output: SG%sgs th? g#%^#$ chào^#^$#!abc35 sgs 35 hello world không gsg class Program { static void Main(string[] args) { string inputString = “SG@%@sgs thể g#%@^@#$ chào^#^$#!abc35| _ sgs _35
How to check Palindrome word using C#
Palindrome word can be read in both direction. Suppose “level” can be read in both direction, so it is palindrome word. To check palindrome word you can try like following code using C#. class Program { public static bool IsPalindrome(string word) { int minLength = 0; int maxLength = word.Length – 1; while (true) {
How to find prime number between 1 to n
class Program { static void Main(string[] args) { //int n = 100000; int n = 0; Console.WriteLine(“Type an integer number to get prime number between 1 to n”); Int32.TryParse(Console.ReadLine(), out n); PrintPrimes(n); } public static void PrintPrimes(int n) { bool isPrime = false; for (int i = 2; i < n; i++) { isPrime =
Draw star pyramid using C#
Sample input: 5 Sample output: Code: /*Author: Md. Mahedee Hasan*/ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StarPyramid { class Program { static void Main(string[] args) { Console.WriteLine(“Enter a number to draw pyramid: “); int nRow = 0; nRow = Convert.ToInt32(Console.ReadLine()); for (int row = 1; row