Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Articles
Page 602 of 2544
How to get TypeCode in C#?
To get TypeCode in C#, the code is as follows −Exampleusing System; public class Demo { public static void Main(){ string s = "Demo"; Console.WriteLine("String = " +s); Console.WriteLine("String Type = " +s.GetType()); Console.WriteLine("GetTypeCode = " +s.GetTypeCode()); } }OutputThis will produce the following output −String = Demo String Type = System.String GetTypeCode = StringExampleLet us now see another example −using System; public class Demo { public static void Main(){ int i = 100; double d = 5.26d; ...
Read MoreFind a permutation such that number of indices for which gcd(p[i], i) > 1 is exactly K in C++
Suppose we have two integers N and K. We have to find a permutation of integers from the range [1 to N] such that the number of indices (1 – base indexing) where gcd(P[i], i) > 1 is exactly K. So if N = 4 and K = 3, then output will be [1, 2, 3, 4], as gcd(1, 1) = 1, gcd(2, 2) = 2, gcd(3, 3) = 3, gcd(4, 4) = 4If we observe it carefully, we can find that gcd(i, i+1) = 1, gcd(1, i) = 1 and gcd(i, i) = i. As the GCD of any ...
Read MoreRemove elements from a SortedSet that match the predicate in C#
To remove elements from a SortedSet that match the predicate, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { private static bool demo(int i) { return ((i % 10) == 0); } public static void Main(String[] args) { SortedSet set1 = new SortedSet(); set1.Add(200); set1.Add(215); set1.Add(310); set1.Add(500); set1.Add(600); Console.WriteLine("SortedSet elements..."); foreach (int i in set1) { Console.WriteLine(i); } ...
Read MoreFind maximum value of x such that n! % (k^x) = 0 in C++
Suppose we have two integers n and k. We have to find the maximum value of x, such that n! mod (k^x) = 0. So when n = 5, and k = 2, then output will be 3. As n! = 120, now for different values of x, it will be −120 mod 2^0 = 0, 120 mod 2^1 = 0, 120 mod 2^2 = 0, 120 mod 2^3 = 0, 120 mod 2^4 = 8, 120 mod 2^5 = 24, 120 mod 2^6 = 56, 120 mod 2^7 = 120. As the max value of x = 3, the ...
Read MoreGet or set the value associated with specified key in ListDictionary in C#
To get or set the value associated with specified key in ListDictionary, the code is as follows −Exampleusing System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { ListDictionary dict = new ListDictionary(); dict.Add("A", "Books"); dict.Add("B", "Electronics"); dict.Add("C", "Appliances"); dict.Add("D", "Pet Supplies"); dict.Add("E", "Clothing"); dict.Add("F", "Footwear"); Console.WriteLine("Value associated with key C = "+dict["C"]); } }OutputThis will produce the following output −Value associated with key C = AppliancesExampleLet us see another example −using System; using System.Collections; using ...
Read MoreCheck if two StringCollection objects are equal in C#
To check if two StringCollection objects are equal, the code is as follows −Exampleusing System; using System.Collections.Specialized; public class Demo { public static void Main() { StringCollection strCol1 = new StringCollection(); strCol1.Add("Accessories"); strCol1.Add("Books"); strCol1.Add("Electronics"); Console.WriteLine("StringCollection1 elements..."); foreach (string res in strCol1) { Console.WriteLine(res); } StringCollection strCol2 = new StringCollection(); strCol2.Add("Accessories"); strCol2.Add("Books"); strCol2.Add("Electronics"); Console.WriteLine("StringCollection2 elements..."); foreach (string ...
Read MoreHow to perform a specified action on each element of the List in C#?
To perform a specified action on each element of the List, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { public static void demo(int s){ s = s * 10; Console.WriteLine(s); } public static void Main(String[] args){ List list = new List(); list.Add(25); list.Add(50); list.Add(75); list.Add(100); list.Add(200); list.Add(250); list.Add(275); list.Add(300); Console.WriteLine("List..."); foreach (int i ...
Read MoreCheck if two StringDictionary objects are equal or not in C#
To check if two StringDictionary objects are equal or not, the code is as follows −Exampleusing System; using System.Collections.Specialized; public class Demo { public static void Main() { StringDictionary strDict1 = new StringDictionary(); strDict1.Add("A", "John"); strDict1.Add("B", "Andy"); strDict1.Add("C", "Tim"); strDict1.Add("D", "Ryan"); strDict1.Add("E", "Kevin"); strDict1.Add("F", "Katie"); strDict1.Add("G", "Brad"); StringDictionary strDict2 = new StringDictionary(); strDict2.Add("A", "John"); strDict2.Add("B", "Andy"); strDict2.Add("C", "Tim"); strDict2.Add("D", "Ryan"); ...
Read MoreHow to play Beep sound through Console in C#?
To play beep sound through Console, the code is as follows −Exampleusing System; public class Demo { public static void Main(String[] args){ Console.WriteLine("Displaying standard output stream..."); Console.WriteLine("Standard Output Stream = "+Console.Out); Console.WriteLine("Beep sound through Console"); Console.Beep(); } }OutputThis will produce the following output −Displaying standard output stream... Standard Output Stream = System.IO.TextWriter+SyncTextWriter Beep sound through ConsoleExampleLet us now see another example −using System; public class Demo { public static void Main(String[] args){ Console.WriteLine("Displaying standard output stream..."); Console.WriteLine("Standard Output Stream ...
Read MoreFind all combinations of k-bit numbers with n bits set where 1 <= n <= k in sorted order in C++
Suppose we have a number k. Find all possible combinations of k- bit numbers with n set-bits where 1
Read More