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 sudhir sharma
Page 15 of 98
C/C++ Tricky Programs
Here are 10 tricky C programming challenges that will test your understanding of language fundamentals and creative problem-solving techniques. 1. Program to Print Double Quotes in C Printing double quotes in C requires escape sequences since quotes are used to delimit string literals. We use the backslash escape sequence " to print quotes − #include int main() { printf(""Tutorials Point ""); return 0; } "Tutorials Point " 2. Print Numbers 1 to 10 Without Loops or Goto When loops and ...
Read MoreC/C++ Program for Greedy Algorithm to find Minimum number of Coins
A greedy algorithm is an algorithmic approach used to find an optimal solution for the given problem. Greedy algorithm works by finding locally optimal solutions (optimal solution for a part of the problem) of each part so that the global optimal solution can be found. In this problem, we will use a greedy algorithm to find the minimum number of coins/notes that could makeup to the given sum. For this we will take under consideration all the valid coins or notes i.e. denominations of { 1, 2, 5, 10, 20, 50, 100, 200, 500, 2000 }. We need to ...
Read MoreC Program to Find the minimum sum of factors of a number?
The minimum sum of factors of a number is the sum of all prime factors (with repetition) of that number. This approach decomposes the number into its smallest possible factors, which are prime numbers, resulting in the minimum possible sum. Syntax int findMinSumOfFactors(int n); Explanation To find the minimum sum of factors, we need to find all possible ways to factorize the number and compare their sums. The minimum sum is always achieved by using prime factorization − Input: n=12 Output: 7 Following are different ways to factorize 12 and ...
Read MoreC Program to Compute Quotient and Remainder?
Given two numbers dividend and divisor, we need to write a C program to find the quotient and remainder when the dividend is divided by the divisor. In division, we see the relationship between the dividend, divisor, quotient, and remainder. The number which we divide is called the dividend. The number by which we divide is called the divisor. The result obtained is called the quotient. The number left over is called the remainder. 55 ÷ 9 = 6 and 1 Dividend Divisor Quotient Remainder Syntax quotient = dividend / divisor; remainder = ...
Read MoreC Program To Check whether Matrix is Skew Symmetric or not?
A square matrix A is said to be skew-symmetric if Aij = −Aji for all i and j. In other words, a matrix A is skew-symmetric if the transpose of matrix A equals the negative of matrix A (AT = −A). Note that all main diagonal elements in a skew-symmetric matrix are zero. Syntax // Check if matrix[i][j] == -matrix[j][i] for all i, j if (A[i][j] == -A[j][i]) { // Matrix is skew-symmetric } Example Matrix Let's take an example of a 3×3 matrix − A = ...
Read MoreC Program for Rat in a Maze - Backtracking-2?
Rat in a maze is a popular problem that utilizes backtracking algorithm. In this problem, we have a 2D matrix representing a maze where some cells are blocked and we need to find a path from source to destination. A maze is a 2D matrix in which some cells are blocked. One of the cells is the source cell, from where we have to start, and another is the destination where we have to reach. We must find a path from source to destination without moving into any blocked cells. Input Maze: ...
Read MoreC Program to Check if count of divisors is even or odd?
Given a number “n” as an input, this program finds whether the total number of divisors of n is even or odd. A divisor of a number is any integer that divides the number without leaving a remainder. An even number is an integer that is exactly divisible by 2. Example: 0, 8, -24 An odd number is an integer that is not exactly divisible by 2. Example: 1, 7, -11, 15 Syntax // Count divisors and check if count is even or odd for (int i = 1; i
Read MoreC Program for array rotation?
Array rotation is a fundamental operation where elements of an array are shifted to the left or right by a specified number of positions. In left rotation, elements move left and the leftmost elements wrap around to the end. Left Rotation by 3 positions Original: 1 2 3 4 ...
Read MoreC Program for Pancake sorting?
Pancake sorting is a variation of the sorting problem where the only allowed operation is to reverse elements of some prefix of the sequence. It's named after the problem of sorting a stack of pancakes using a spatula that can flip all pancakes above any insertion point. Syntax void pancakeSort(int arr[], int n); void flip(int arr[], int i); How Pancake Sort Works The algorithm works by repeatedly finding the maximum element in the unsorted portion and moving it to its correct position using at most two flip operations − Step 1: Find ...
Read MoreC/C++ Program for Finding the Number Occurring Odd Number of Times?
In C programming, finding the number that occurs an odd number of times in an array is a common problem. Given an array where all elements appear an even number of times except one, we need to identify that unique element. Consider the array [1, 2, 1, 3, 3, 2, 2]. Here, the number 2 appears 3 times (odd), while others appear even times. Example Scenarios Input: arr[] = {5, 7, 8, 8, 5, 8, 8, 7, 7} Output: 7 The number 7 appears 3 times (odd frequency). Input: arr[] = {2, 3, 2, 1, ...
Read More