Found 1401 Articles for C

Arc function in C

sudhir sharma
Updated on 16-Oct-2019 07:12:56

2K+ Views

In the C programming language, there is an option to create an arc of a circle of a given radius with a given center coordinates and degree of the arc.The arc() function is used to create an arc. This arc function is included in graphics.h library in C which contains methods that can draw figures on the output screen.Syntaxvoid arc(int x, int y, int startangle, int endangle, int radius);Now, let's get deep into the function and understand each parameter passed and output returned by the function.Parametersx − type = int, function: defines the x coordinate of the center of the arc.y ... Read More

Advanced master theorem for divide and conquer recurrences

sudhir sharma
Updated on 08-Jun-2020 05:44:13

2K+ Views

Divide and conquer is an algorithm that works on the paradigm based on recursively branching problem into multiple sub-problems of similar type that can be solved easily.ExampleLet’s take an example to learn more about the divide and conquer technique −function recursive(input x size n)    if(n < k)       Divide the input into m subproblems of size n/p.       and call f recursively of each sub problem    else       Solve x and returnCombine the results of all subproblems and return the solution to the original problem.Explanation − In the above problem, the problem ... Read More

Grand Central Dispatch (GCD)

Arnab Chakraborty
Updated on 11-Oct-2019 12:48:37

635 Views

Grand Central Dispatch (GCD) - a technology for Apple’s Mac OS X and iOS operating systems-is a combination of extensions to the C language, an API, and a run-time library that allows application developers to identify sections of code to run in parallel. Like OpenMP, GCD manages most of the details of threading. GCD identifies extensions to the C and C++ languages known as blocks. A block is simply a self-contained unit of work. It is specified by a caret ˆ inserted in front of a pair of braces { }. A simple example of a block is shown below ... Read More

What is OpenMP?

Arnab Chakraborty
Updated on 11-Oct-2019 12:45:48

7K+ Views

OpenMP is a set of compiler directives as well as an API for programs written in C, C++, or FORTRAN that provides support for parallel programming in shared-memory environments. OpenMP identifies parallel regions as blocks of code that may run in parallel. Application developers insert compiler directives into their code at parallel regions, and these directives instruct the OpenMP run-time library to execute the region in parallel. The following C program illustrates a compiler directive above the parallel region containing the printf() statement −#include #include int main(int argc, char *argv[]){    /* sequential code */    #pragma omp ... Read More

Windows Anonymous Pipe

Arnab Chakraborty
Updated on 11-Oct-2019 12:18:27

849 Views

Windows anonymous pipes are actually Ordinary pipes, and they behave similarly to their UNIX counterparts: they are unidirectional and employ parent-child relationships between the communicating processes. In addition, reading and writing to the pipe can be accomplished with the ordinary ReadFile() and WriteFile() functions. The Windows API use CreatePipe() function for creating pipes, which is passed four parameters. The parameters provide separate handles forreading andwriting to the pipeAn instance of the STARTUPINFO structure, used to specify that the child process is to inherit the handles of the pipe.the size (in Bytes) of the pipe may be specified.Windows requires the programmer ... Read More

C/C++ Pointer Puzzle?

sudhir sharma
Updated on 07-Oct-2019 08:19:16

286 Views

A Pointer is a variable that stores the address of another variable. The data type of the pointer is the same as the data type as the variable.In this puzzle you need to know the size of the pointer that is being used. The puzzle checks our understanding of pointers by asking you the size of variable.The size of int is 4 bytes, whereas the size of int pointer is 8. Now, let’s test your skills with the following exercise in c++ programming language.Example Live Demo#include using namespace std; int main() {    int a = 6 ;    int ... Read More

C/C++ Function Call Puzzle?

sudhir sharma
Updated on 07-Oct-2019 08:14:43

143 Views

This C/C++ function call puzzle is a puzzle that is intended to explore more about the behaviour of method calling in both the programming languages C and C++/.The output of a method in C and C++ is different. Lets see what is the difference in calling methods in C and C++.Let’s take an example and check the output of the below code in c and c++.Example Live Demovoid method() {    // Print statement } int main() {    method();    method(2); }OutputFor C++ −Error : too many arguments to function ‘void method()’For C −Program runs without any error.Logic behind the ... Read More

C program to copy the contents of one file to another file?

sudhir sharma
Updated on 01-Nov-2023 14:17:59

36K+ Views

C Files I/O − Create, Open, Read, Write and Close a File C File management A File can be used to store a large volume of persistent data. Like many other languages 'C' provides the following file management functions, Creation of a file Opening a file Reading a file Writing to a file Closing a file Following are the most important file management functions available in 'C, ' function ... Read More

C program to check if a given string is Keyword or not?

sudhir sharma
Updated on 07-Oct-2019 07:28:38

10K+ Views

Keyword is a predefined or reserved word which is available in C++ library with a fixed meaning and used to perform an internal operation. C++ Language supports more than 64 keywords.Every Keyword exists in lower case letters like auto, break, case, const, continue, int etc.32 Keywords in C++ Language which is also available in the C language.autodoubleintstructbreakelselongswitchcaseenumregistertypedefcharexternreturnunionconstfloatshortunsignedcontinueforsignedvoiddefaultgotosizeofvolatiledoifstaticwhileThese are 30 reserved words that were not in C, but added to C++asmdynamic_castnamespacereinterpret_castboolexplicitnewstatic_castcatchfalseoperatortemplateclassfriendprivatethisconst_castinlinepublicthrowdeletemutableprotectedtruetrytypeidtypenameusingusingusingwchar_tInput: str=”for” Output: for is a keywordExplanationKeywords are reserved words which cannot be used as variable names in program.There are 32 keywords in the C programming language.Compare the string with each ... Read More

Sum of the series 1.2.3 + 2.3.+ … + n(n+1)(n+2) in C

sudhir sharma
Updated on 07-Oct-2019 07:23:56

508 Views

Find the sum up to n terms of the series: 1.2.3 + 2.3.4 + … + n(n+1)(n+2). In this 1.2.3 represent the first term and 2.3.4 represent the second term.Let’s see an example to understand the concept better, Input: n = 5 Output: 420Explanation1.2.3 + 2.3.4 + 3.4.5 + 4.5.6 + 5.6.7 = 6 + 24 + 60 + 120 + 210 = 420nth term = n(n+1)(n+2); where n = 1, 2, 3, …= n(n^2+3n+2)=n^3 +3n^2 +2nNow, noteSum =n(n+1)/2 ; if nth term =n=n(n+1)(2n+1)/6 ; if nth term =n^2=n^2(n+1)^2/4 ; if nth term =n^3Hence the required sum =n^2(n+1)^2 /4 + ... Read More

Advertisements