Programming Articles

Page 926 of 2547

C Program to delete n characters in a given string

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

In C programming, deleting n characters from a specific position in a string involves shifting the remaining characters to fill the gap. This operation modifies the original string by removing a substring starting from a given position. Syntax void deleteString(char str[], int position, int n); Algorithm The algorithm to delete n characters from a given position in a string is as follows − Step 1 − Read the input string Step 2 − Read the starting position for deletion Step 3 − Read the number of characters to delete Step 4 − ...

Read More

C program to find GCD of numbers using recursive function

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

The greatest common divisor (GCD) of two numbers is the largest positive integer that divides both numbers evenly. In C programming, we can find the GCD using the Euclidean algorithm implemented with a recursive function. Syntax unsigned int GCD(unsigned i, unsigned j); Algorithm The recursive GCD algorithm follows these steps − Step 1 − Define the recursive function. Step 2 − Read the two integers a and b. Step 3 − Call recursive function with the following logic: a. if j > i then return GCD(j, i) b. if ...

Read More

C program to calculate sum of series using predefined function

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

In C programming, calculating the sum of mathematical series is a common task. This program demonstrates how to calculate the sum of the series: 1 - n²/2! + n⁴/4! - n⁶/6! + n⁸/8! - n¹⁰/10! using the predefined pow() function from the math.h library. Syntax double pow(double base, double exponent); Algorithm The algorithm to calculate the sum of series using predefined function − Step 1: Read the value of n from user Step 2: Initialize factorial = 1, sum = 1, and loop counter Step 3: For each even power from 2 ...

Read More

C program to count characters, lines and number of words in a file

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

In C programming, counting characters, words, and lines in a file is a common file processing task. This operation reads through a file character by character and keeps track of different elements based on specific delimiters. Syntax FILE *fopen(const char *filename, const char *mode); int fgetc(FILE *stream); int fclose(FILE *stream); File Operations Overview The three basic operations that we can perform on files are − Open a file − Using fopen() function Process file − Read, write, or modify file contents Save and close file − Using fclose() function Example: ...

Read More

C program to remove a line from the file

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

In C, removing a line from a file requires creating a temporary file because files cannot be modified directly in place. The process involves reading the original file line by line, copying all lines except the target line to a temporary file, then replacing the original file. Syntax FILE *fopen(const char *filename, const char *mode); char *fgets(char *str, int n, FILE *stream); int fputs(const char *str, FILE *stream); int remove(const char *filename); int rename(const char *oldname, const char *newname); Algorithm The algorithm to remove a line from a file follows these steps − ...

Read More

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
Showing 9251–9260 of 25,466 articles
« Prev 1 924 925 926 927 928 2547 Next »
Advertisements