Found 1358 Articles for C

C Program to Find if there is any subarray with a sum equal to 0

AYUSH MISHRA
Updated on 17-Apr-2025 15:42:28

31 Views

What is a Subarray? A subarray is a contiguous part of the array. The sum of elements in a subarray is the cumulative sum of elements of a subarray. For example: in the given array [1, 2, 3, 4, 5, 6] the subarray is [3, 4, 5]. In this article, we are given an array and need to find if any subarray has a sum equal to zero using C. Example 1 Input: arr[] = {4, 2, -3, 1} Output: Yes Explanation: The subarray {2, -3, 1} has a sum equal to 0. Example 2 ... Read More

Program to Rotate a matrix by 90 degrees in the clockwise direction in C

AYUSH MISHRA
Updated on 17-Apr-2025 13:29:28

39 Views

In this article, we are given an N x N matrix, and our task is to rotate it by 90 degrees clockwise in C. Example Input: [1 2 3], [4 5 6], [7 8 9] Output: [7 4 1], [8 5 2], [9 6 3] Below are different approaches to rotate a matrix by 90 degrees in the clockwise direction: Using Brute Force Approach Using In-Place Rotation Using Brute Force Approach This is the simple and direct approach to understand and implement. In this approach, we create a ... Read More

C program to Implement Kadane’s Algorithm

Akansha Kumari
Updated on 25-Apr-2025 14:13:32

129 Views

We are given an array of integers, and we need to find the maximum sum of a contiguous subarray using Kadane’s Algorithm. Kadane’s Algorithm is an efficient way to find the maximum subarray sum in O(n) time complexity. For example, in the array {-2, 1, -3, 4, -1, 2, 1, -5, 4}, the subarray [4, -1, 2, 1] has the maximum sum 6. In this article, we are going to implement Kadane's algorithm using C. What Is Kadane's Algorithm? Kadane's algorithm is a popular and optimal algorithm used to find the maximum sum of a contiguous subarray in a given ... Read More

C Program to Find an Automorphic Number

AYUSH MISHRA
Updated on 06-Jan-2025 19:01:50

4K+ Views

Problem Description We are given a number and we have to check whether it is an automorphic number or not. An Automorphic Number is a number whose square ends with the number itself. For example, 52 = 25 (ends with 5), so 5 is an Automorphic Number. In this article, we will learn how to check whether a given number is an automorphic number or not in C. Examples Consider the following examples, which ... Read More

Maximum count of characters that can replace ? by at most A 0s and B 1s with no adjacent duplicates

Thanweera Nourin A V
Updated on 31-Oct-2023 17:54:57

690 Views

The aim of this article is to implement a program maximum count of characters that can replace? by at most A 0s and B 1s with no adjacent duplicates. Given a couple of integers A and B, both of which that represent the number of 0s and 1s that are accessible, and a string Str with only the special characters "*" and "?" The aim is to determine the greatest number of characters that may be used in the '?' position without causing any neighboring characters to be identical. Example 1 Let us give the input string str = ... Read More

Position of the leftmost set bit in a given binary string where all 1s appear at the end

Thanweera Nourin A V
Updated on 31-Oct-2023 15:53:13

271 Views

The aim of this article is to implement a program to Position the leftmost set bit in a given binary string where all 1s appear at the end. A string of bits is known as a binary string. A binary string is utilized for storing non-traditional data, such as images, as opposed to a character string, which typically holds text data. The quantity of bytes in a binary string determines its length. Binary data, or data that is portrayed in a binary (base-2) version instead of a text (base-10) format, is stored in binary string variables in computer programming. ... Read More

largest string formed by choosing words from a given Sentence as per given Pattern

Ravi Ranjan
Updated on 16-Apr-2025 15:58:58

234 Views

To find the largest string formed by choosing words from a given sentence, a user should know about the lexicographically largest string. A lexicographically largest string is a string, when sorted alphabetically, it would appear at the last if we form all possible strings from the selected words. For example: {lion, zebra, apple} will be lexicographically sorted as {apple, lion, zebra}. In this article, we have been given a string and a pattern. Based on this pattern, we have to find the lexicographically largest string matching the given pattern by choosing words from the sentence using C. Here is an ... Read More

Find the count of Alphabetic and Alphanumeric strings from given Array of Strings

Thanweera Nourin A V
Updated on 31-Oct-2023 16:08:30

347 Views

The aim of this article is to implement a program to find the count of alphabetic and alphanumeric strings from a given array of strings. As we know, a string is a group of characters that ends with the null character "\0" in C programming. Characters from the C string are kept in a character array. A C string differs from a character array in that it ends with the distinctive character "\0." Input arr[] = {“snmd”, “nej7dnr”, “snmd”, “dltmdj”, “lbwm2p6”} Output 3 2 “snmd”: 2 “nej7dnr”: 1 “dltmdj”: 1 “lbwn2p6”: 1 Explanation The strings ... Read More

Count of sum of “10” subsequences for each 1 in string with A 1s, B 10s and C 0s

Thanweera Nourin A V
Updated on 31-Oct-2023 15:58:43

183 Views

The aim of this article is to implement a program to obtain the count of sum of “10” subsequences for each 1 in string with A 1s, B 10s and C 0s. Example Let us take the Input: A = 1, B = 2, C = 3 Output obtained here is : 14 Explanation A = 1 denotes. There is a single "1" string, B = 2 denotes, there is a pair of "10" strings, and C = 3 denotes, there is a trio of "0" strings. The string that results from concatenation is "11010000". Five ... Read More

Convert a string Str1 to Str2 by moving B to right and A to left without crossover

Thanweera Nourin A V
Updated on 31-Oct-2023 16:00:18

179 Views

The aim of this article is to implement a program to convert a string Str1 to Str2 by moving B to right and A to left without crossover. As we know, a string is a group of characters that ends with the null character "\0" in C programming. Characters from the C String are kept in a character array. A C string differs from a character array in that it ends with the distinctive character "\0". Example Let us take the input strings, str1 = “#B#A#”, and str2 = “##BA#” Output obtained here is: Yes Explanation − 'B' ... Read More

Advertisements
close