Found 2594 Articles for Csharp

140 Views
In this problem, we are given an array of integers that may contain both positive and negative integers. We have to calculate the maximum sum of any contiguous subarray of the given array. In this article, we are going to learn how we can find the maximum subarray sum using the Kadane Algorithm using C#. Here is an example to find maximum sum in subarray: Example Input: arr = [1, -2, 3, 4, -1, 2, 1, -5, 4] Maximum Sum Subarray: [3, 4, -1, 2, 1] Sum = 3 + 4 + (-1) + 2 + 1 = 9 ... Read More

666 Views
In this problem, we are given a number n, and we need to find the position of the first set bit (1-bit) in its binary representation. In this article, we are going to discuss different approaches to solving this problem using C#. Example 1 Input: N = 18 Output: 2 Explanation: The binary representation of 18 is 10010. The first set bit from the right is at position 2. Example 2 Input: N = 12 Output: 3 Explanation: The binary ... Read More

1K+ Views
What is a Cuboid? A cuboid is a three-dimensional figure with six rectangular faces, where opposite faces are equal in dimensions. We can calculate the volume, perimeter, and surface area of a cuboid using specific formulas based on its length, breadth, and height. Problem Statement Given length, breadth, and height. You need to find its volume, perimeter, and surface area using different approaches in C#. Formulas for Cuboid Calculations The following are the formulas for the volume, perimeter, and surface area of a cuboid: The Volume of a Cuboid: Volume = length × breadth × height The ... Read More

5K+ Views
We are given a number N, and we need to calculate the sum of the first N natural numbers. In this article, we are going to learn how we can find the sum of the first N natural numbers in C#. Example 1 Input: N = 3 Output: 6 Explanation − The first 3 natural numbers are: 1, 2, 3 The sum of these numbers is: 1 + 2 + 3 = 6 Example 2 Input: N = 5 Output: 15 Explanation − The first 5 natural numbers are: 1, 2, 3, 4, 5 ... Read More

2K+ Views
Problem Description In this problem, we are given a number, and we need to convert it to its equivalent Roman number representation using C#. Example 1 Input: number = 58 Output: Roman numeral = LVIII Explanation: 58 in Roman numerals is written as L (50) + V (5) + III (3). Example 2 Input: number = 1994 Output: Roman numeral = MCMXCIV Explanation: 1994 in Roman numerals is written as M (1000) + CM (900) + XC (90) + IV ... Read More

4K+ Views
Problem Description In this problem, we are given a number n, and we need to calculate the sum of the squares of the first N natural numbers. In this article, we are going to discuss different approaches to solving this problem using C#. Example 1 Input: N = 4 Output: 30 Explanation: The squares of the first 4 natural numbers are: 1, 4, 9, 16. The sum of the numbers is: 1 + 4 + 9 + 16 = 30. Example 2 Input: ... Read More

4K+ Views
Natural numbers are a set of positive integers, which are commonly used for counting and ordering. They begin from 1 and continue infinitely. In some contexts, it may also include 0. Here, we are going to learn about different approaches to removing all odd numbers from a given array using C#. Problem Description We are given an array and need to remove all the even numbers from it. The resulting array should only contain odd numbers. In this article, we are going to discuss different approaches to solving this problem using C#. Example 1 Input: array ... Read More

4K+ Views
Problem Description We are given a number N, and we need to calculate the sum of the cubes of the first N natural numbers. In this article, we are going to learn how we can find the sum of cubes of the first N natural numbers C#. Example 1 Input: N = 3 Output: 36 Explanation: The cubes of the first 3 natural numbers are: 13 = 1, 23 = 8, 33 = 27 The sum of these cubes is:1 + 8 ... Read More

3K+ Views
Natural numbers are a set of positive integers, which are commonly used for counting and ordering. They begin from 1 and continue infinitely. In some contexts, it may also include 0. Here, we are going to learn about different approaches to removing all odd numbers from a given array using C#. Problem Description We are given an array, and we need to remove all the odd numbers from it. The resulting array should only contain even numbers. Example 1 Input: array = {1, 2, 3, 4, 5, 6} Output: {2, ... Read More

4K+ Views
Problem Description In this problem, we are given two numbers, and we have to find the value obtained after subtracting one number from another. In this article, we are going to learn how we can subtract two numbers in C# using different approaches. Example 1 Input:number1 = 8number2 = 12 Output: 4 Explanation The subtraction of number2 - number1, i.e., 12 - 8, will result in 4. Example 2 Input:number1 = 10number2 = 10 Output: 0 ... Read More