Found 26504 Articles for Server Side Programming

C program to find GCD of numbers using recursive function

Bhanu Priya
Updated on 31-Aug-2021 13:17:25

26K+ Views

ProblemFind the greatest common divisor (GCD) for the given two numbers by using the recursive function in C programming language.SolutionThe solution to find the greatest common divisor (GCD) for the given two numbers by using the recursive function is as follows −AlgorithmRefer an algorithm given below to find the greatest common divisor (GCD) for the given two numbers by using the recursive function.Step 1 − Define the recursive function.Step 2 − Read the two integers a and b.Step 3 − Call recursive function.a. if i>j b. then return the function with parameters i, j c. if i==0 d. then return ... Read More

C program to calculate sum of series using predefined function

Bhanu Priya
Updated on 31-Aug-2021 13:14:41

916 Views

ProblemThe program to calculate the sum of the following expressionSum=1-n^2/2!+n^4/4!-n^6/6!+n^8/8!-n^10/10!User has to enter the value of n at runtime to calculate the sum of the series by using the predefined function power present in math.h library function.SolutionIt is explained below how to calculate sum of series using predefined function.AlgorithmRefer an algorithm given below to calculate sum of series by using the predefined function.Step 1 − Read the num valueStep 2 − Initialize fact = 1, sum = 1 and n =5Step 3 − for i= 1 to n   a. compute fact= fact*i    b. if i %2 = 0    c. ... Read More

C program to display all prime numbers between 1 to N using for loop

Bhanu Priya
Updated on 07-Nov-2023 04:05:41

88K+ Views

ProblemWrite a C program to display all the prime numbers between 1 and n is a value given by the user at run time.SolutionC program to display all the prime numbers between 1 and n is a value given by the user at run time is explained below −AlgorithmGiven below is an algorithm to display all the prime numbers between 1 and n is a value given by the user at run time.Step 1 − Read n value.Step 2 − Initialize count = 0Step 3 − for i = 2 to n   a. for j = 1 to i    b. ... Read More

What is function prototype in C language

Bhanu Priya
Updated on 31-Aug-2021 13:07:17

1K+ Views

A function is a self-contained block that carries out a specific well-defined task.Types of functionsFunctions are broadly classified into two types which are as follows −Predefined functionsUser defined functionsCommunications among functionsFunctions communicate among themselves by using arguments and return value.Farm of ‘C’ function for return-datatype function name (argument list) is as follows −{    local variable declarations;    executable statements(s);    return (expression); }For Example, void mul (int x, int y).{    int p;    p=x*y;    printf(“product = %d”, p); }Prototype functionsThese functions can be done in two ways as explained below −Create a copy of the function declaration ... Read More

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

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

15K+ 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

14K+ 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

10K+ 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

4K+ 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

3K+ 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

Combining two Series into a DataFrame in Pandas

Rishikesh Kumar Rishi
Updated on 30-Aug-2021 12:23:44

2K+ Views

To combine two series into a DataFrame in Pandas, we can take two series and concatenate them using concat() method.StepsCreate series 1 with two elements, where index is ['a', 'b'] and name is Series 1.Print Series 1.Make Series 2 with two elements, where index is ['a', 'b'] and name is Series 2.Print Series 2.Concatenate Pandas objects along a particular axis with optional set logic along the other axes.Print the resultant DataFrame.Example Live Demoimport pandas as pd s1 = pd.Series([4, 16], index=['a', 'b'], name='Series 1') print "Input series 1 is: ", s1 s2 = pd.Series([3, 9], index=['a', 'b'], name='Series 2') print "Input series 2 is: ... Read More

Advertisements