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 Bhanu Priya
Page 16 of 106
C program to rotate the bits for a given number
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 MoreC Program to check whether the triangle is equilateral, isosceles or scalene
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 MoreC Program to calculate the difference between two time periods
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 MoreC program to find maximum occurrence of character in a string
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 MoreWrite a C Program to count the frequency of each character
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 MoreExplain the Character operations in C language
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 MoreExplain the pointers to unions in C language
A union in C is a memory location that is shared by several variables of different data types. A pointer to union is a variable that stores the address of a union, allowing us to access union members using the arrow operator (->) just like with structures. Syntax union uniontag { datatype member1; datatype member2; /* ... */ datatype membern; }; union uniontag *ptr; // Pointer to union Declaration of Union and Pointer There are different ...
Read MoreWhat is a structure at local scope in C language?
In C, a structure defined within a function or block has local scope, meaning it is only accessible within that specific function or block. This is different from global structures that can be accessed throughout the program. Syntax struct tagname { datatype member1; datatype member2; datatype member_n; }; When declared inside a function, the structure definition and its variables are local to that function. Example 1: Basic Local Structure Here's a simple example showing a structure declared within the main() function ...
Read MoreHow to pass an entire structure as an argument to function in C?
In C programming, structures can be passed to functions in three ways. Here we'll focus on passing an entire structure as an argument to a function, where the complete structure variable is passed by value. Syntax return_type function_name(struct structure_name variable_name); When passing an entire structure as an argument − The structure variable name is given as argument in the function call It is collected in another structure variable in the function header A complete copy of the structure is created, which uses additional memory Example 1: Basic Structure Passing This ...
Read MoreHow to pass the individual members as arguments to function using structure elements?
In C programming, there are three ways to pass structure data to functions. One of the most basic approaches is passing individual structure members as separate arguments to a function. This method treats each structure member as an independent variable in the function call. Syntax // Function declaration returnType functionName(dataType1 member1, dataType2 member2, ...); // Function call functionName(structVariable.member1, structVariable.member2, ...); How It Works Each member is passed as a separate argument in the function call Members are collected independently as ordinary variables in the function parameters Changes made to parameters inside the ...
Read More