Programming Articles - Page 2474 of 3366

C Program to count the number of lines in a file?

sudhir sharma
Updated on 20-Aug-2019 08:49:43

9K+ Views

In this program, we are going to learn how to find the total number of lines available in a text file using C program?This program will open a file and read the file’s content character by character and finally return the total number of lines in the file. To count the number of lines we will check the available Newline () characters.Input: File "test.text"    Hello friends, how are you?    This is a sample file to get line numbers from the file. Output: Total number of lines are: 2ExplanationThis program will open a file and read the file’s content ... Read More

C Program to Compute Quotient and Remainder?

sudhir sharma
Updated on 20-Aug-2019 08:47:43

443 Views

Given two numbers dividend and divisor. The task is to write a program to find the quotient and remainder of these two numbers when the dividend is divided by the divisor.In division, we will 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 RemainderInput: Dividend = 6 Divisor = 2 Output: Quotient = 3, Remainder = ... Read More

C Program To Check whether Matrix is Skew Symmetric or not?

sudhir sharma
Updated on 20-Aug-2019 08:44:46

4K+ Views

Square Matrix A is said to be skew-symmetric if aij=−aji for all i and j. In other words, we can say that matrix A is said to be skew-symmetric if transpose of matrix A is equal to negative of Matrix A i.e (AT=−A).Note that all the main diagonal elements in the skew-symmetric matrix are zero.lets take an example of a matrixA= |0 -5 4| |5 0 -1| |-4 1 0|It is skew-symmetric matrix because aij=−aji for all i and j. Example, a12 = -5 and a21=5 which means a12=−a21. Similarly, this condition holds true ... Read More

C Program for Rat in a Maze - Backtracking-2?

sudhir sharma
Updated on 20-Aug-2019 10:25:14

3K+ Views

Rat in a maze is also one popular problem that utilizes backtracking. IA 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 one of them is the destination, where we have to reach. We have to find a path from the source to the destination without moving into any of the blocked cell. A picture of an unsolved maze is shown below.And this is its solution.To solve this puzzle, we first start with the source cell and move in a direction where ... Read More

C Program to Check if count of divisors is even or odd?

sudhir sharma
Updated on 20-Aug-2019 08:34:59

467 Views

Given a number “n” as an input, this program is to find the total number of divisors of n is even or odd. An even number is an integer that is exactly divisible by 2. Example: 0, 8, -24An odd number is an integer that is not exactly divisible by 2. Example: 1, 7, -11, 15Input: 10 Output: EvenExplanationFind all the divisors of the n and then check if the total number of divisors are even or odd. To do this find all divisor and count the number and then divide this number by 2 to check if it is ... Read More

C Program for array rotation?

sudhir sharma
Updated on 26-Dec-2024 11:15:54

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

C Program for Pancake sorting?

sudhir sharma
Updated on 20-Aug-2019 08:31:34

289 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

Alternate vowel and consonant string in C/C++?

Nishu Kumari
Updated on 04-Aug-2025 16:36:50

446 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

C/C++ Program for Finding the Number Occurring Odd Number of Times?

sudhir sharma
Updated on 01-Aug-2025 17:48:12

443 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

C/C++ Program to Find the sum of Series with the n-th term as n^2 – (n-1)^2

sudhir sharma
Updated on 20-Aug-2019 08:24:03

321 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

Advertisements