Found 1401 Articles for C

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

Bhanu Priya
Updated on 31-Aug-2021 12:58:48

11K+ Views

A file is a physical storage location on disk and a directory is a logical path which is used to organise the files. A file exists within a directory.The three operations that we can perform on file are as follows −Open a file.Process file (read, write, modify).Save and close file.ExampleConsider an example given below −Open a file in write mode.Enter statements in the file.The input file is as follows −Hi welcome to my world This is C programming tutorial From tutorials PointThe output is as follows −Number of characters = 72Total words = 13Total lines = 3ProgramFollowing is the C ... Read More

C program to print hollow rectangle star pattern

Bhanu Priya
Updated on 31-Aug-2021 12:55:09

12K+ Views

Here, we will print hollow rectangle star(*) pattern by using for loop in C programming language.Consider an example given below −InputEnter number of rows: 5OutputThe output is as follows −***** *    * *    * *    * *****AlgorithmAn algorithm is given below to explain how to print hollow rectangle star(*) pattern by using for loop.Step 1 − Input number of rows to print at runtime.Step 2 − Use outer for loop for rows from 1 to N.for(i=1; i

C program to remove a line from the file

Bhanu Priya
Updated on 31-Aug-2021 12:51:33

9K+ Views

A file is a physical storage location on disk and a directory is a logical path which is used to organise the files. A file exists within a directory.The three operations that we can perform on file are as follows −Open a file.Process file (read, write, modify).Save and close file.AlgorithmAn algorithm is given below to explain the C program to remove a line from the file.Step 1 − Read file path and line number to remove at runtime.Step 2 − Open file in read mode and store in source file.Step 3 − Create and open a temporary file in write ... Read More

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

Bhanu Priya
Updated on 31-Aug-2021 12:49:33

3K+ Views

A file is a physical storage location on disk and a directory is a logical path which is used to organise the files. A file exists within a directory.The three operations that we can perform on file are as follows −Open a file.Process file (read, write, modify).Save and close file.ProgramFollowing is the C program to store even, odd and prime numbers into separate files − Live Demo#include #include /* Function declarations */ int even(const int num); int prime(const int num); int main(){    FILE * fptrinput,    * fptreven,    * fptrodd,    * fptrprime;    int num, success; ... Read More

C program to change the file name using rename() function

Bhanu Priya
Updated on 01-Sep-2021 09:08:30

2K+ Views

The rename function changes a file or directory from oldname to newname. This operation is just like a move operation. Hence, we can also use this rename function to move a file.This function is present in stdio.h library header files.The syntax of rename function is as follows −int rename(const char * oldname, const char * newname);Function of rename()It accepts two parameters. One is oldname and another is newname.These two parameters are pointer to constant character, which define old and new name of file.If file renamed is successful, then it returns zero otherwise, it returns a non-zero integer.During the rename operation ... Read More

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

Bhanu Priya
Updated on 26-Mar-2021 08:03:25

2K+ Views

ProblemWrite a program to print heart shaped pattern with the name in centre using for loop.SolutionThe user has to enter the name that should be printed in centre along with the number of rows the stars has to be print.AlgorithmRefer an algorithm given below to print the name in heart pattern by using for loop.Step 1 − Declare variables.Step 2 − Read a name at runtime that should be printed on centre.Step 3 − Read number of rows.Step 4 − Find the length of name.Step 5 − Print upper part of the heart.Step 6 − Print lower part of the ... Read More

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

Bhanu Priya
Updated on 26-Mar-2021 07:57:51

3K+ Views

Linked lists use dynamic memory allocation i.e. they grow and shrink accordingly. It is collection of nodes.Node has two parts which are as follows −DataLinkTypes of Linked ListsThe types of linked lists in C programming language are as follows −Single / Singly linked listsDouble / Doubly linked listsCircular single linked listCircular double linked listAlgorithmRefer an algorithm given below for storing the car information by using the dynamic linked list.Step 1 − Declare structure variables.Step 2 − Declare Function definition to display.Step 3 − Allocate dynamic memory allocation to variable.Step 4 − Use do while loop to enter the car information.Step ... Read More

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

Bhanu Priya
Updated on 26-Mar-2021 07:54:54

2K+ Views

In C programming language, we can find the area of circle, area and volume of cylinder with the help of structures.The logic used to find area of circle is as follows −s.areacircle = (float)pi*s.radius*s.radius;The logic used to find area of cylinder is as follows −s.areacylinder = (float)2*pi*s.radius*s.line + 2 * s.areacircle;The logic used to find the volume of cylinder is −s.volumecylinder = s.areacircle*s.line;AlgorithmRefer an algorithm given below to find the area of circle and cylinder along with other parameters by using structures.Step 1 − Declare structure members.Step 2 − Declare and initialize the input variables.Step 3 − Enter length and ... Read More

What is an anagram in C language?

Bhanu Priya
Updated on 26-Mar-2021 07:52:46

3K+ Views

Anagram strings are nothing but, all the characters that occur for the same number of times in another string, which we call as anagrams.A user enters two strings. We need to count how many times each letter ('a' to 'z') appears in them and then, compare their corresponding counts. The frequency of an alphabet in a string is how many times it appears in it.If two strings have same count of the frequency of particular alphabet then, we can say those two strings are anagrams.Example 1String 1 − abcdString 2 − bdacThese two strings have same letters which appear once. ... Read More

C Program find nCr and nPr.

Bhanu Priya
Updated on 26-Mar-2021 07:50:25

14K+ 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.Permutations and combinations formulasThe formulas to find the permutation and combination of given numbers in C language are given below −nCr = n!/(r!*(n-r)!)nPr = n!/(n-r)!.The logic used to find nCr is as follows −result = factorial(n)/(factorial(r)*factorial(n-r));The logic used to find nPr is as follows −result ... Read More

Advertisements