Found 2595 Articles for Csharp

C# Program to Subtract Two Numbers

AYUSH MISHRA
Updated on 09-Jan-2025 12:06:16

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

C# Program to Return Quadrant in which the Coordinate Lie

AYUSH MISHRA
Updated on 06-Jan-2025 19:13:12

4K+ Views

Cartesian-coordinate System and Quadrants The cartesian-coordinate system is divided into four Quadrants: Quadrant I, Quadrant II, Quadrant III, and Quadrant IV. In this article, we are going to learn how we can determine the quadrant in which given points i.e., x and y, lie in C#. Problem Description We are given the position of a point (x, y), and we have to determine in which quadrant the given point lies in C#. Example 1 Input: (-6, 4) Output: Quadrant II Example 2 Input: (1, 2) ... Read More

C# Program to Check if a Number is Perfect

AYUSH MISHRA
Updated on 16-Dec-2024 12:49:42

2K+ Views

What is a Perfect Number?A perfect Number is a positive integer that is equal to the sum of its proper divisors(excluding itself). For example, 6 is a perfect number because its divisors (1, 2, and 3) sum up to 6. Proper divisors are those numbers that leave no remainder when divided by numbers. The proper divisor should not include that number itself otherwise it would always be greater than a number.Problem DescriptionIn this article, we will learn how to check whether a number is a perfect number or not using C#.Below are a few examples including edge case examples to ... Read More

C# Program to Check If a Number is a Happy Number

AYUSH MISHRA
Updated on 13-Dec-2024 21:46:55

3K+ Views

Problem DescriptionWe are given a number as input, we have to check whether the number is a happy number or not. In this article, we are going to learn how we can check if a number is a happy number or not in C#. What is a happy number?A happy number is a special type of number that will at last become equal to 1 when we replace the number with the sum of the square of its digits again and again. If the number is stuck in the loop such that it never becomes equal to 1 then the ... Read More

C# program to check if a matrix is symmetric

AYUSH MISHRA
Updated on 12-Dec-2024 12:29:56

2K+ Views

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 other simple words, we can say that a matrix is called a symmetric matrix if it is a square matrix that is equal to its transpose. Below are a few examples of understanding a symmetric matrix: ... Read More

C# Program to Remove Duplicates from an Array

AYUSH MISHRA
Updated on 12-Dec-2024 12:46:59

3K+ Views

In this article, we are going to check how we can remove duplicate elements from an array in C# using different approaches. What are Duplicate Elements in an Array? The elements which exist more than once in a given array are duplicate elements. In this problem, we are given an array, and we have to remove duplicate elements and print unique elements. Examples Input: array = {1, 1, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6} Output:array = {1, 2, 3, 4, 5} Explanation: After removing the duplicate elements, the remaining elements are 1, 2, ... Read More

C# program to count prime numbers in an array

AYUSH MISHRA
Updated on 06-Dec-2024 11:34:03

3K+ Views

Prime numbers are natural numbers greater than 1 with only two factors: 1 and themselves. Examples include 2, 3, 5, 7, etc. The smallest prime number is 2. Problem Description We are given an array and need to find the number of prime numbers in the array using C#. Below is an example to understand the problem: Examples Input: array = { 3, 6, 12, 7, 9, 11} Output: array = {3, 7, 11} Explanation: The numbers 3, 7, and 11 have only two factors: 1 and themselves, so they are prime numbers. Input: array = {4, ... Read More

C# Program to Find Prime Numbers Within a Range

AYUSH MISHRA
Updated on 04-Dec-2024 12:41:48

4K+ Views

In this article, we are going to discuss how we can find prime numbers present within a given range using C#. What are prime numbers? Prime numbers are sets of natural numbers greater than 1 that have only two factors i.e. 1 and itself. They have no other positive divisors other than 1 and itself. Examples of prime numbers are 2, 3, 5, 7, etc. Which is the Smallest prime number? The smallest prime number is 2. Is 1 a prime Number? No, 1 is not a prime number. Problem Description We are given two numbers which are starting and ... Read More

C# Program to Check if an Array is Sorted

AYUSH MISHRA
Updated on 04-Dec-2024 13:07:19

4K+ Views

Problem Description We are given an array, we have to check whether the array is sorted or not. The array can be sorted in both ascending or descending order. In this article, we are going to discuss different approaches to check if an array is sorted or not using C#. Example Input: array = {1, 2, 3, 4, 5} Output: True Explanation: The array is sorted in ascending order. Input: array = {29, 28, 27, 26, ... Read More

C# Program to Reverse a Number

AYUSH MISHRA
Updated on 04-Dec-2024 12:56:24

3K+ Views

Reversing a number is a simple and fundamental question in the world of programming. Problem Description In this problem, we are given an integer n and we have to reverse its digit and print the reversed number. In this article, we are going to discuss different approaches to reverse a number in C#. Example Input Number = 12345 Output Reversed Number = 54321 Explanation: 54321 is the reversed form of the input number 12345 from its original order. Input Number = 8299 Output Reversed Number = 9928 Explanation: 9928 is the reversed form of the input number 8299 ... Read More

Advertisements