C Articles

Page 41 of 96

Print the Mirror Image of Sine-Wave Pattern in C

suresh kumar
suresh kumar
Updated on 15-Mar-2026 456 Views

In C programming, creating a mirror image of a sine-wave pattern involves printing a visual representation where waves appear to be reflected. This pattern uses the mathematical concept of symmetry to create wave-like shapes using characters. Syntax for(i = 1; i

Read More

Program to Print the Squared Matrix in Z form in C

suresh kumar
suresh kumar
Updated on 15-Mar-2026 757 Views

In C programming, printing a squared matrix in Z form means displaying the elements in a specific pattern − first the top row, then the diagonal elements from top-right to bottom-left, and finally the bottom row. This creates a Z-shaped traversal pattern through the matrix. Syntax /* Z-form traversal pattern */ // First row: matrix[0][0] to matrix[0][n-1] // Diagonal: matrix[i][n-1-i] where i goes from 1 to n-2 // Last row: matrix[n-1][1] to matrix[n-1][n-1] Algorithm 1 2 3 ...

Read More

Program to print Lower triangular and Upper triangular matrix of an array in C

suresh kumar
suresh kumar
Updated on 15-Mar-2026 13K+ Views

In C, triangular matrices are special square matrices where elements are zero either above or below the main diagonal. This program demonstrates how to print both lower and upper triangular matrices from a given matrix. Syntax /* Lower Triangular: matrix[i][j] = 0 when j > i */ /* Upper Triangular: matrix[i][j] = 0 when i > j */ Triangular Matrix Types Lower Triangular Matrix − A square matrix where all entries above the main diagonal are zero. Lower Triangular ...

Read More

Why is a[i] == i[a] in C/C++ arrays?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 399 Views

In C programming, there's an interesting feature where array subscript notation a[i] can also be written as i[a]. This happens because of how C internally handles array indexing through pointer arithmetic. Syntax a[i] == i[a] // Both expressions are equivalent How It Works In C, E1[E2] is defined as (*((E1) + (E2))). The compiler performs pointer arithmetic internally to access array elements. Because the binary + operator is commutative, a[i] becomes *(a + i), and i[a] becomes *(i + a). Since addition is commutative, both expressions evaluate to the same memory ...

Read More

How to sort an array of dates in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 1K+ Views

In C programming, sorting an array of dates requires creating a structure to represent dates and implementing a custom comparison function. We use the qsort() function from the standard library to sort the array based on chronological order. Syntax void qsort(void *base, size_t num, size_t size, int (*compare)(const void *, const void *)); Method 1: Using qsort() with Custom Comparator This approach uses a structure to store date components and a comparison function that compares dates chronologically − #include ...

Read More

Print colored message with different fonts and sizes in C

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 3K+ Views

In C programming, the graphics.h library provides functions to customize text output with different colors, fonts, and sizes. This library is primarily used in graphics programming to create visually appealing text displays on the screen. Note: The graphics.h library requires Turbo C/C++ or compatible compilers. For modern compilers, you may need to install graphics libraries like WinBGIm or use alternative approaches. Key Graphics Functions for Text Formatting 1. setcolor() Function The setcolor() function changes the color of the output text − Syntax void setcolor(int color); Example #include ...

Read More

C Program for Activity Selection Problem

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 6K+ Views

The activity selection problem is a classic optimization problem where we are given a set of activities with their starting and finishing times. The goal is to select the maximum number of activities that can be performed by a single person, given that only one activity can be performed at a time. This problem is efficiently solved using a greedy algorithm approach. The greedy algorithm makes locally optimal choices at each step, hoping to find a global optimum. It selects activities based on their finishing times in ascending order. Syntax void activitySelection(int start[], int finish[], int ...

Read More

C / C++ Program for Subset Sum (Backtracking)

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 12K+ Views

Backtracking is a technique to solve dynamic programming problems. It works by going step by step and rejects those paths that do not lead to a solution and trackback (moves back) to the previous position. In the subset sum problem, we have to find the subset of a set such that the elements of this subset sum up to a given number K. All the elements of the set are positive and unique (no duplicate elements are present). Syntax void subset_sum(int s[], int t[], int s_size, int t_size, int sum, int index, int target_sum); ...

Read More

Matrix Multiplication and Normalization in C program

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 945 Views

In C programming, matrix multiplication and normalization are fundamental operations in linear algebra. Matrix multiplication follows specific rules where the number of columns in the first matrix must equal the number of rows in the second matrix. Matrix normalization scales each row so that its Euclidean norm equals 1. Syntax // Matrix Multiplication for (i = 0; i < rows1; i++) { for (j = 0; j < cols2; j++) { for (k = 0; k < cols1; k++) { ...

Read More

C Program for Naive algorithm for Pattern Searching

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 8K+ Views

Pattern matching in C is the process of finding if a string (pattern) is present within another string (text). For example, the string "algorithm" is present within the string "naive algorithm". If found, its location (starting position) is displayed. The Naive algorithm is a simple brute-force approach that checks every possible position in the text. Syntax void naivePatternSearch(char text[], char pattern[]); Algorithm The Naive Pattern Searching algorithm works as follows − naive_algorithm(pattern, text) Input − The text and the pattern Output − locations where the pattern is present in the text ...

Read More
Showing 401–410 of 953 articles
« Prev 1 39 40 41 42 43 96 Next »
Advertisements