Csharp Articles

Page 88 of 196

How to find the average of elements of an integer array in C#?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 296 Views

The following is our integer array −int[] myArr = new int[6] {    8,    4,    2,    5,    9,    14 };Firstly, get the length of the array, and loop through the array to find the sum of the elements. After that, divide it with the length.int len = myArr.Length; int sum = 0; int average = 0; for (int i = 0; i < len; i++) {    sum += myArr[i]; } average = sum / len;Here is the complete codeExampleusing System; public class Program {    public static void Main() {       int[] ...

Read More

How to find the product of two binary numbers using C#?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 672 Views

To find the product of two binary numbers, firstly set them.val1 = 11100; val2 = 10001; Console.WriteLine("Binary one: "+val1); Console.WriteLine("Binary two: "+val2);Now loop through to get the product.while (val2 != 0) {    digit = val2 % 10;    if (digit == 1) {       val1 = val1 * factor;       prod = displayMul(val1, prod);    } else    val1 = val1 * factor;    val2 = val2 / 10;    factor = 10; } Console.WriteLine("Product = {0}", prod);Above a method displayMul() is called with the first binary number.static long displayMul (long val1, long val2) ...

Read More

How to find the length and rank of a jagged array in C#?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 449 Views

Firstly, set a jagged array.int[][] arr = new int[][] {    new int[] {       0,       0    }, new int[] {       1,       2    },    new int[] {       2,       4    }, new int[] {       3,       6    }, new int[] {       4,       8    } };Now, use the GetLowerBound(), GetUpperBound() and Rank property to get the lenth and rank of the array as shown in the following code ...

Read More

How to find the Rank of a given Array in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 335 Views

To find the rank of an array, use the Rank property.Firstly, declare and initialize an array.int[,] myArr = new int[3,3];Now, get the rank.myArr.RankLet us see the complete code −Exampleusing System; class Demo {    static void Main() {       int[,] myArr = new int[3,3];       Console.WriteLine("Rank of Array : " + myArr.Rank);    } }OutputRank of Array : 2

Read More

How to find Volume and Surface Area of a Sphere using C#?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 419 Views

For volume and surface area of a sphere, firstly declare a variable with the value of radius.int r = 15;Get the volume f the sphere.// calculating volume of sphere cal_volume = (4.0 / 3) * (22 / 7) * r * r * r;Now the surface area of the sphere is calculated −cal_area = 4 * (22 / 7) * r * r;Let us see the complete code −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       double cal_area, cal_volume, r;       // radius       r ...

Read More

How to find the size of a list in C#?

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 4K+ Views

Declare and initialize a list.var products = new List (); products.Add("Accessories"); products.Add("Clothing"); products.Add("Footwear");To get the size, use the Capacity property.products.CapacityNow let us see the complete code to find the size of a list.Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       var products = new List ();       products.Add("Accessories");       products.Add("Clothing");       products.Add("Footwear");       Console.WriteLine("Our list....");       foreach(var p in products) {          Console.WriteLine(p);       }       Console.WriteLine("Size of list = " + products.Capacity);    } }OutputOur list.... Accessories Clothing Footwear Size of list = 4

Read More

C# program to find the most frequent element

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

Let’s say our string is −String s = "HeathLedger!";Now create a new array.int []cal = new int[maxCHARS];Create a new method and pass both the string and the new array in it. Find the maximum occurrence of a character.static void calculate(String s, int[] cal) {    for (int i = 0; i < s.Length; i++)    cal[s[i]]++; }Let us see the complete code −Exampleusing System; class Demo {    static int maxCHARS = 256;    static void calculate(String s, int[] cal) {       for (int i = 0; i < s.Length; i++)       cal[s[i]]++;    } ...

Read More

How to find the size of a variable without using sizeof in C#?

Syed Javed
Syed Javed
Updated on 11-Mar-2026 2K+ Views

To get the size of a variable, sizeof is used.int x; x = sizeof(int);To get the size of a variable, without using the sizeof, try the following code −// without using sizeof byte[] dataBytes = BitConverter.GetBytes(x); int d = dataBytes.Length;Here is the complete code.Exampleusing System; class Demo {    public static void Main() {       int x;       // using sizeof       x = sizeof(int);       Console.WriteLine(x);       // without using sizeof       byte[] dataBytes = BitConverter.GetBytes(x);       int d = dataBytes.Length;       Console.WriteLine(d);    } }Output4 4

Read More

Find frequency of each word in a string in C#

Samual Sam
Samual Sam
Updated on 11-Mar-2026 864 Views

To find the frequency of each word in a string, you can try to run the following code −Exampleusing System; class Demo {    static int maxCHARS = 256;    static void calculate(String s, int[] cal) {       for (int i = 0; i < s.Length; i++)       cal[s[i]]++;    }    public static void Main() {       String s = "Football!";       int []cal = new int[maxCHARS];       calculate(s, cal);       for (int i = 0; i < maxCHARS; i++)       if(cal[i] > 1) ...

Read More

How to find the Sum of two Binary Numbers using C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

To find the sum of two binary numbers, firstly set them.val1 = 11110; val2 = 11100;Now call the displaySum() method, which created to display the sumL.sum = displaySum(val1, val2);We have set a new array in the method to display each bit of the binary number.long[] sum = new long[30];Now let us see the complete code to calculate the sum of binary numbers as shown in the code below −Exampleusing System; class Demo {    public static void Main(string[] args) {       long val1, val2, sum = 0;       val1 = 11110;       val2 = ...

Read More
Showing 871–880 of 1,951 articles
« Prev 1 86 87 88 89 90 196 Next »
Advertisements