Programming Articles

Page 941 of 2547

C Program to find two's complement for a given number

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 18K+ Views

The two's complement is a mathematical operation used to represent negative numbers in binary form. It can be calculated using two methods − Method 1 − Convert the given binary number into one's complement and then add 1. Method 2 − Starting from the rightmost bit, copy all bits until the first '1' (including it), then complement all remaining bits. Syntax // One's complement: flip all bits // Two's complement: one's complement + 1 How Two's Complement Works The two's complement process involves these steps − Find the one's ...

Read More

What is enumerated data type in C language?

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 3K+ Views

An enumerated data type in C is a user-defined data type that allows programmers to create variables with a restricted set of named values. It provides a way to assign names to integer constants, making code more readable and maintainable. The keyword is enum. Syntax enum tagname { identifier1, identifier2, ..., identifier_n }; Basic Example Here's how to declare an enumeration for days of the week − enum week { mon, tue, wed, thu, fri, sat, sun }; By default, identifier ...

Read More

C Program to delete the duplicate elements in an array

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 55K+ Views

In C programming, removing duplicate elements from an array means creating a new array that contains only unique elements. This is a common array manipulation task that helps eliminate redundancy in data. Syntax for(i = 0; i < size; i++) { for(j = i + 1; j < size; j++) { if(arr[i] == arr[j]) { // Shift elements left to remove duplicate ...

Read More

C Program to count trailing and leading zeros in a binary number

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 3K+ Views

In C programming, counting trailing and leading zeros in a binary representation of a number is a common bit manipulation task. Trailing zeros are the consecutive zeros from the least significant bit (LSB) until the first set bit, while leading zeros are the consecutive zeros from the most significant bit (MSB) until the first set bit. Syntax /* For trailing zeros */ int countTrailingZeros(int number); /* For leading zeros */ int countLeadingZeros(int number); Trailing Zeros Trailing zeros are the zeros that appear after the rightmost set bit (1) when counting from ...

Read More

C program to rotate the bits for a given number

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 3K+ Views

Bit rotation is a fundamental bitwise operation where bits in a number are shifted circularly. In left rotation, bits move left and the leftmost bit wraps to the rightmost position. In right rotation, bits move right and the rightmost bit wraps to the leftmost position. Syntax // Left rotation int leftRotate(int num, int rotations); // Right rotation int rightRotate(int num, int rotations); Key Concepts Left rotation: Bits are shifted left, MSB wraps to LSB position Right rotation: Bits are shifted right, LSB wraps to MSB position Circular shift: No bits ...

Read More

C Program to check whether the triangle is equilateral, isosceles or scalene

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 65K+ Views

A triangle consists of three sides and three angles. Based on the relationship between the three sides, triangles can be classified into three types − Equilateral triangle: All three sides are equal. Isosceles triangle: Any two sides are equal. Scalene triangle: No sides are equal. Syntax if (side1 == side2 && side2 == side3) { // Equilateral triangle } else if (side1 == side2 || side2 == side3 || side1 == side3) { // Isosceles triangle } else { // Scalene triangle ...

Read More

C Program to calculate the difference between two time periods

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 4K+ Views

In C programming, calculating the difference between two time periods is a common problem that involves handling the borrowing mechanism similar to subtraction in arithmetic. This program takes two time periods as input and computes their difference in hours, minutes, and seconds format. Syntax struct time { int hrs; int min; int sec; }; void diff_between_time(struct time start, struct time stop, struct time *diff); Algorithm The logic to find the difference between start and stop time involves borrowing when the stop ...

Read More

C program to find maximum occurrence of character in a string

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 4K+ Views

In C programming, finding the character with maximum occurrence in a string involves counting the frequency of each character and determining which appears most often. This is useful for text analysis and character statistics. Syntax int frequency[ASCII_SIZE]; while(string[i] != '\0') { frequency[(int)string[i]]++; i++; } Algorithm The algorithm to find maximum occurrence follows these steps − Initialize a frequency array to count occurrences of each ASCII character Traverse the string and increment frequency count for each character Find the character with maximum frequency count ...

Read More

Write a C Program to count the frequency of each character

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 959 Views

In C programming, counting the frequency of each character in a string is a common task that involves scanning through the string and tracking how many times each character appears. Syntax int frequency[26]; // For lowercase letters a-z frequency[character - 'a']++; // Increment count for character Algorithm Step 1: Define maximum string size Step 2: Declare string and frequency array Step 3: Read input string Step 4: Initialize frequency array to 0 Step 5: Iterate through string and count characters: - For lowercase: frequency[string[i] - 'a']++ ...

Read More

Explain the Character operations in C language

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 720 Views

Character operations in C language involve handling individual characters, which can be alphabetic (A-Z or a-z), numeric (0-9), whitespace, or special symbols. C provides various functions for character input, output, and manipulation. Syntax char variable_name = 'character'; char variable_name; Character Declaration Characters in C are declared using the char data type and can be initialized with character constants − #include int main() { char a = 'A'; /* using character constant */ char b = ...

Read More
Showing 9401–9410 of 25,466 articles
« Prev 1 939 940 941 942 943 2547 Next »
Advertisements