C Articles

Page 9 of 96

C program to store even, odd and prime numbers into separate files

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

In C, we can read numbers from a file and categorize them into even, odd, and prime numbers, storing each category in separate files. This involves file I/O operations and number classification algorithms. Syntax FILE *fopen(const char *filename, const char *mode); int fscanf(FILE *stream, const char *format, ...); int fprintf(FILE *stream, const char *format, ...); int fclose(FILE *stream); Note: This program requires creating an input file named "numbers.txt" with integers to process. Since file operations cannot be executed in the online compiler, the code structure is shown for educational purposes. Example ...

Read More

C program to print name inside heart pattern using for loop.

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

In C programming, creating a heart pattern with a name in the center is an interesting application of nested for loops. This program generates a heart shape using asterisks (*) and displays a user-entered name in the middle of the pattern. Syntax // Basic heart pattern structure for(i = start; i = end; i--) { // Lower triangular part } Algorithm Follow these steps to create a heart pattern with name − Step 1: Declare variables for loop counters, name array, and pattern size Step 2: Read the ...

Read More

C program to store the car information using dynamic linked list.

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

A linked list is a dynamic data structure that grows and shrinks during runtime using dynamic memory allocation. It consists of nodes, where each node contains data and a pointer to the next node. This makes it ideal for storing variable amounts of data like car information. Node Structure Each node in a linked list has two main components − Data − Stores the actual information (car model, color, year) Link − Pointer to the next node in the list Types of Linked Lists The types of linked lists in C programming are ...

Read More

C program to find the area of circle and cylinder using structures.

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

In C programming, we can calculate the area of a circle and the surface area and volume of a cylinder using structures to organize related data. A structure helps group related geometric properties like radius, height, and calculated areas in a single unit. Syntax struct shape { float radius; float height; float areacircle; float areacylinder; float volumecylinder; }; Formulas Used Area of circle: π × radius² Surface area of cylinder: 2π × radius ...

Read More

What is an anagram in C language?

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

An anagram is a word or phrase formed by rearranging the letters of another word or phrase, using all original letters exactly once. In C programming, we check if two strings are anagrams by comparing the frequency of each character in both strings. Two strings are anagrams if they contain the same characters with the same frequency, regardless of their order. For example, "listen" and "silent" are anagrams because both contain one 'l', one 'i', one 's', one 't', one 'e', and one 'n'. Syntax int check_anagram(char str1[], char str2[]); Algorithm The anagram ...

Read More

C Program find nCr and nPr.

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

In C programming language, nCr is referred as the combination. nCr is the selection of r objects from a set of n objects, where the order of objects does not matter. nPr is referred as the permutation. nPr is arrangement of 'r' objects from a set of 'n' objects, which should be in an order or sequence. Syntax nCr = n! / (r! * (n-r)!) nPr = n! / (n-r)! Permutations and Combinations Formulas The formulas to find the permutation and combination of given numbers in C language are given below − ...

Read More

C program to perform intersection operation on two arrays

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

In C programming, an array intersection operation finds all common elements between two arrays. The intersection of two arrays contains only the elements that appear in both arrays, without duplicates. Syntax for(i=0; i

Read More

C program to perform union operation on two arrays

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

The union operation on arrays combines all elements from both arrays while eliminating duplicates. This is similar to the mathematical set union operation, where each element appears only once in the result. Syntax int unionArrays(int arr1[], int size1, int arr2[], int size2, int result[]); Union Operation Example Given two arrays: Array 1 = {1, 2, 3, 4, 6} Array 2 = {1, 2, 5, 6, 7} The union operation produces: Array1 ∪ Array2 = {1, 2, 3, 4, 5, 6, 7} Array 1 ...

Read More

What is a simple assertion in C language?

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

An assertion is a statement used to declare positively that a fact must be true when that line of code is reached. Assertions are debugging tools that help catch programming errors during development by validating expected conditions. Syntax assert(expression); Where expression is a condition that should evaluate to true. The assert() macro is defined in the assert.h header file. How Assertions Work True condition: When the expression is true, the program continues normally with no action. False condition: When the expression is false, the program terminates and displays an error message with ...

Read More

C Program to find sum of perfect square elements in an array using pointers.

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

In C programming, finding the sum of perfect square elements in an array using pointers involves traversing the array with pointer arithmetic and checking if each element is a perfect square. A perfect square is a number that can be expressed as the product of an integer with itself (e.g., 1, 4, 9, 16, 25). Syntax int isPerfectSquare(int num); int sumPerfectSquares(int *arr, int size); Algorithm Step 1 − Read the number of elements in the array. Step 2 − Input the array elements. Step 3 − Initialize sum = 0 and declare a pointer ...

Read More
Showing 81–90 of 953 articles
« Prev 1 7 8 9 10 11 96 Next »
Advertisements