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
-
Economics & Finance
Articles by AYUSH MISHRA
Page 2 of 12
C# Program to Subtract Two Numbers
In this article, we will learn how to subtract two numbers in C# using different programming approaches. Subtraction is one of the fundamental arithmetic operations where we find the difference between two values. Problem Description Given two numbers, we need to find the result of subtracting one number from another. We'll explore multiple methods to perform this operation in C#. 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 ...
Read MoreMaximum Subarray Sum - Kadane Algorithm using C#
The Maximum Subarray Sum problem involves finding the contiguous subarray within a given array of integers that has the largest sum. Kadane's Algorithm is the most efficient approach to solve this problem in linear time. Given an array that may contain both positive and negative integers, we need to find the maximum sum of any contiguous subarray. Here is an 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 MoreC# Program to Remove Duplicates from an Array
In this article, we will explore how to remove duplicate elements from an array in C# using different approaches. Removing duplicates is a common programming task that helps maintain data integrity and optimize storage. What are Duplicate Elements in an Array? Duplicate elements are values that appear more than once in an array. When removing duplicates, we keep only one occurrence of each unique value, creating a new array with distinct elements. Examples Input: array = {1, 1, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6} Output: array = {1, 2, 3, 4, ...
Read MoreC# program to check if a matrix is symmetric
In this article, we are going to discuss how we can check if a matrix is symmetric or not using C#. What is a Symmetric Matrix? A symmetric matrix is a square matrix (matrix which has the same number of rows and columns) in which the element at position A[i][j] is equal to the element at A[j][i] for all i and j. In simple words, a matrix is called symmetric if it is equal to its transpose. Symmetric Matrix Property Original Matrix 1 2 3 ...
Read MoreC# Program to Check If a Number is a Happy Number
We are given a number as input, and we need to check whether it is a happy number or not. In this article, we will learn how to check if a number is a happy number using C#. What is a Happy Number? A happy number is a number that eventually becomes equal to 1 when we repeatedly replace it with the sum of the squares of its digits. If the number gets stuck in a cycle and never reaches 1, then it is not a happy number. Happy Number Process ...
Read MoreC# Program to Check if a Number is Perfect
A perfect number is a positive integer that equals the sum of its proper divisors (all divisors excluding the number itself). For example, 6 is perfect because its proper divisors (1, 2, and 3) sum to 6. Proper divisors are numbers that divide evenly into the given number without leaving a remainder. Perfect Number: 6 1 2 3 = 6 6 ÷ 1 = 6 6 ÷ 2 = ...
Read MoreFind the Angle Between Hour and Minute Hands of a Clock in C#
The calculation of the angle between the hour and minute hands of a clock is a common problem in logical reasoning and programming. This calculation is used in various applications, such as analog clock simulations, scheduling software, and time-based animations. In this article, we will discuss how to calculate the angle between the hour and minute hands of a clock in C# using different approaches. What is the Angle Between the Hour and Minute Hands? The angle between the hour and minute hands is determined based on the positions of both hands on the clock face. Key ...
Read MoreRemove all odd numbers from an array in C#
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, 4, 6} Explanation: ...
Read MoreFind the sum of cubes of the first N natural numbers in C#
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 in C#. Problem Description The task is to compute the sum: 1³ + 2³ + 3³ + ... + N³ for a given positive integer N. Example 1 Input: N = 3 Output: 36 Explanation: The cubes of the first 3 natural numbers are − 1³ = 1, ...
Read MoreRemove all even numbers from an array in C#
Removing all even numbers from an array is a common programming task that involves filtering out numbers divisible by 2. In C#, we can accomplish this using various approaches such as iterative methods, LINQ, or recursion to create a new array containing only odd numbers. 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. An even number is any integer that is divisible by 2 (i.e., number % 2 == 0), while an odd number leaves a remainder of 1 when divided ...
Read More