Posts

Showing posts from June, 2019

How to Remove Duplicate characters from String in C#

Image
Hello All, In this Program, I will show you, how to make a program to remove duplicate characters from strings using c# using System; using System.Collections.Generic; namespace testconsole { class Program { static void Main(string[] args) { string Stringvalue = "this is Apple"; string result = ""; Console.WriteLine("Before remove duplicate character :{0} ", Stringvalue); foreach (char ch in Stringvalue) { if(result.Contains(ch.ToString())) { } else { result = result + ch; } } Console.WriteLine("after remove duplicate character :{0} ", result); Console.ReadKey(); } } }

How to Check any value in Array element is duplicate or not in C#

Image
In this article, I will show you how to make a simple program to check any value is duplicate or not in Array. It will return true if the value exists duplicate in Array else false. using System; using System.Collections.Generic; namespace testconsole { class Program { static void Main(string[] args) { Console.WriteLine(checkduplicate(1,2,3,2,2)); Console.ReadLine(); } public static bool checkduplicate(params int[] A) { Dictionary<int, int> d = new Dictionary<int, int>(); foreach (int i in A) { if (d.ContainsKey(i)) return true; else d.Add(i, 1); } return false; } } }

How to get Remainder value of 2 integers in c#

Image
Hello all, In  this program, we can get the Remainder value of  2 integers in c# using System; using System.Collections.Generic; using System.Text; namespace testconsole { class Program { static void Main(string[] args) { Console.WriteLine("Enter First Value"); int firstvalue =Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Second Value"); int secondvalue = Convert.ToInt32(Console.ReadLine()); int remainder; if (secondvalue==0) { Console.WriteLine("Second value can't be zero"); } else if (firstvalue<secondvalue) { Console.WriteLine("First value can't be lessthan second value"); } remainder = (firstvalue % secondvalue); Console.WriteLine("Remainder: {0}", remainder); Co...

How to find factorial of given number in c# using recursive function

Image
Hello all, In  this program, we can get the factorial value of a number  using the recursive function in c# using System; using System.Collections.Generic; using System.Text; namespace testconsole { class Program { static void Main(string[] args) { Console.WriteLine("Please enter a number"); int number = Convert.ToInt32(Console.ReadLine()); double factorial = factorial_RecursionValue(number); Console.WriteLine("factorial of : " + number + " = " + factorial); Console.ReadLine(); } public static double factorial_RecursionValue(int number) { if (number == 1) return 1; else return number * factorial_RecursionValue(number - 1); } } }

How to find Prime number within Range from 1 to nth in c#

Image
In this Program, you can see how to find Prime number in c#  using for loop using System; using System.Collections.Generic; using System.Text; namespace testconsole { class Program { static void Main(string[] args) { bool isprimenumber = true; Console.WriteLine("Enter nth number"); int totalnumber = Convert.ToInt32(Console.ReadLine()); for (int i = 2; i <= totalnumber; i++) { for (int j = 2; j < totalnumber; j++) { if (i != j && i % j == 0) { isprimenumber = false; break; } } if (isprimenumber) { Console.WriteLine(+i); } isprimenumber = true; } Console.ReadLine(); } } }

How to solve Fizz Buzz Problem in C#

Image
In this article, we will learn here a simple Program where Prints from 1 to 200 and for multiples of  2, it displays "Fizz" and for multiples of 7, it displays Buzz. For numbers which are divided by both 2 and 7, it displays Fizz Buzz. using System; using System.Collections.Generic; using System.Text; namespace testconsole { class Program { static void Main(string[] args) { int totalnumber = 200; int fizz = 2; //2 for fiz int buzz = 7; // 7 for Buz for (int i = 1; i <= totalnumber; i++) { if (i % fizz == 0 && i % buzz == 0) // display FizBuz If number is divide by 2 and 7 { Console.WriteLine("fizz Buzz"); } else if (i % fizz == 0 && i % buzz != 0) // Diplay fiz if number divided by 2 { Console.WriteLine("fizz"); } else if (i % buzz == 0 && i % fizz != 0) // Diplay Buzz if number divided by 7 { Console.WriteLine("Buzz"); } e...