Programming Articles

Page 602 of 2544

How to get TypeCode in C#?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 234 Views

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 More

Find a permutation such that number of indices for which gcd(p[i], i) > 1 is exactly K in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 321 Views

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 More

Remove elements from a SortedSet that match the predicate in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 342 Views

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 More

Find maximum value of x such that n! % (k^x) = 0 in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 227 Views

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 More

Get or set the value associated with specified key in ListDictionary in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 150 Views

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 More

Check if two StringCollection objects are equal in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 192 Views

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 More

How to perform a specified action on each element of the List in C#?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 269 Views

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 More

Check if two StringDictionary objects are equal or not in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 192 Views

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 More

How to play Beep sound through Console in C#?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 323 Views

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 More

Find all combinations of k-bit numbers with n bits set where 1 <= n <= k in sorted order in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 470 Views

Suppose we have a number k. Find all possible combinations of k- bit numbers with n set-bits where 1

Read More
Showing 6011–6020 of 25,433 articles
« Prev 1 600 601 602 603 604 2544 Next »
Advertisements