
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1339 Articles for C

4K+ Views
Write a C program to left rotate an array by n position. How to rotate left rotate an array n times in C programming. Logic to rotate an array to left by n position in C program.Input: arr[]=1 2 3 4 5 6 7 8 9 10 N=3 Output: 4 5 6 7 8 9 10 1 2 3ExplanationRead elements in an array say arr.Read number of times to rotate in some variable say N.Left Rotate the given array by 1 for N times. In real left rotation is shifting of array elements to one position left and copying first ... Read More

275 Views
This C Program Implements Pancake Sort on Array of Integers.Pancake sorting is a variation of the sorting problem in which the only allowed operation is to reverse the elements of some prefix of the sequence.Pancake sorting is the colloquial term for the mathematical problem of sorting a disordered stack of pancakes in order of size when a spatula can be inserted at any point in the stack and used to flip all pancakes above it. A pancake number is the minimum number of flips required for a given number of pancakesInput:5, 3, 2, 1, 4 Output:1 2 3 4 5ExplanationIt ... Read More

428 Views
We are given a string with both vowels and consonants. Our task is to rearrange it so that vowels and consonants appear alternately, while keeping their original order within their groups. This rearrangement is only possible if the number of vowels and consonants is equal, or their difference is exactly one. If multiple valid arrangements are possible, we return the one that is lexicographically smaller. Let's understand this with a few example scenarios. Scenario 1 Input: "objective" Output: "bojecitev" Explanation: Vowels = [o, e, i, e], Consonants = [b, j, c, t, v] Consonants are more by 1 -> valid ... Read More

425 Views
In this article, we implement a C++ program to find the number that occurs an odd number of times in an array, using different approaches. We are given an array containing multiple elements, and our task is to identify the number that appears an odd number of times. For example, consider the array: [1, 2, 1, 3, 3, 2, 2]. In this case, the number 2 appears 3 times, which is odd. Example Scenarios Let's look at a few example scenarios to understand the problem: Input: arr[] = {5, 7, 8, 8, 5, 8, 8, 7, 7} ... Read More

298 Views
There are many types of series in mathematics which can be solved easily in C programming. This program is to find the sum of following of series in C program.Tn = n2 - (n-1)2Find the sum of all of the terms of series as Sn mod (109 + 7) and, Sn = T1 + T2 + T3 + T4 + ...... + TnInput: 229137999 Output: 218194447ExplanationTn can be expressed as 2n-1 to get itAs we know ,=> Tn = n2 - (n-1)2 =>Tn = n2 - (1 + n2 - 2n) =>Tn = n2 - 1 - n2 + 2n ... Read More

9K+ Views
C++ Tokens are the smallest individual units of a program.C++ is the superset of C and so most constructs of C are legal in C++ with their meaning and usage unchanged. So tokens, expressions, and data types are similar to that of C.Following are the C++ tokens : (most of c++ tokens are basically similar to the C tokens)KeywordsIdentifiersConstantsVariablesOperatorsKeywordsKeywords are reserved words which have fixed meaning, and its meaning cannot be changed. The meaning and working of these keywords are already known to the compiler. C++ has more numbers of keyword than C, and those extra ones have special working ... Read More

387 Views
In this program we have to add binary numbers given. there are n binary numbers and we have to add them all to give one binary number as an output.For this we will use binary addition logic and add all the terms from 1 to N one by one to gain the result.Input: "1011", "10", "1001" Output: 10110ExplanationThe easier method is by converting binary string to its decimal equivalent, then add them and convert into binary again. Here we will do the addition manually. We will use one helper function to add two binary strings. That function will be used ... Read More

3K+ Views
In this problem, you are given an integer array arr of size n and an integer S. Your task is to find an element k in the array such that if all the elements greater than k in the array are replaced with k, then the sum of all the elements of the resultant array becomes equal to S. If such an element exists, print it; otherwise, print -1. Scenario 1: Input: int S = 9; int arr[] = { 1, 3, 2, 5, 8 }; Output: ... Read More

921 Views
Here we will see how to perform the matrix addition and subtraction using multithreaded environment. The pthread is used to execute multiple threads simultaneously in C or C++.There are two matrices A and B. Order of each matrix is (m x n). Each thread will take each row, and perform addition or subtraction. So for m rows, there are m different threads.Example#include #include #include #include #define CORE 3 #define MAX 3 using namespace std; int AMat[MAX][MAX] = {{10, 20, 30}, {40, 50, 60}, {70, 80, 50} }; int BMat[MAX][MAX] = {{80, 60, 20}, {30, ... Read More

171 Views
Here we will see how to get the sum of the series with n-th term as n2 – (n-1)2. The recurrence relation is like below −Tn = n2 − (n−1)2So the series is −We need to find S mod (109 + 7), where S is the sum of all terms of the given series.Example#include #define X 1000000007 using namespace std; long long getSum(long long n) { return ((n % X) * (n % X)) % X; } int main() { long long n = 56789; cout