Found 26504 Articles for Server Side Programming

Explain scope rules related to the functions in C language

Bhanu Priya
Updated on 15-Mar-2021 15:22:35

724 Views

Scope rules are related to the following factors −Accessibility of a variables.Period of existence of a variable.Boundary of usage of variables.Scope rules related to functions are as followsFunction which is a self-contained block that performs a particular task.Variables that are declared within the function body are called local variables.These variables only exist inside the specific function that creates them. They are unknown to other functions and to the main functions too.The existence of local variables ends when the function completes its specific task and returns to the calling point.Example 1Following is the C program for scope rules related to functions ... Read More

How to create a frequency table in data frame format in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:23:24

8K+ Views

To create a frequency table in R, we can simply use table function but the output of table function returns a horizontal table. If we want to read the table in data frame format then we would need to read the table as a data frame using as.data.frame function. For example, if we have a table called T then to convert it into a data frame format we can use the command as.data.frame(T).Example1Live Demo> x1 x1Output[1] 2 0 2 3 2 3 1 2 1 4 0 0 4 4 1 3 1 2 1 3 2 3 2 1 ... Read More

How to subset columns that has less than four categories in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:28:48

149 Views

If column is categorical then there can be at least two categories and there is no limit for the total number of categories but it will also depend on the total number of cases. If we have a data frame that contain some categorical columns having more or less categories than 4 then we might want to subset columns having less than four categories. This could be required in situations when we want to subset the data biasedly or have some predefined data characteristics that allows this change. The subset of such columns can be done with the help of ... Read More

How to convert the character values in an R data frame column to lower case?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:32:19

3K+ Views

The character values can be stored in uppercase, lowercase, or a mixture of the two. If we have values that are either in uppercase or the mixture of lower and upper then we can convert those character values to only lowercase by using tolower function. We simply need to pass the vector or column of the data frame inside the tolower function as shown in the below examples.Example1Consider the below data frame −Live Demo> x1 y1 df1 df1Output   x1     y1 1  C  -0.1036851 2  C  -0.6176530 3  B   0.5763786 4  A   0.1943794 5  C   1.1196470 ... Read More

Write a C program to reverse array

Bhanu Priya
Updated on 15-Mar-2021 15:04:15

3K+ Views

An array is a group of related items that store with a common name.SyntaxThe syntax is as follows for declaring an array −datatype array_name [size];InitializationAn array can also be initialized at the time of declaration −int a[5] = { 10, 20, 30, 40, 50};Reversing array in CWe can reverse array by using swapping technique.For example, if 'P' is an array of integers with four elements −P[0] = 1, P[1] = 2, P[2] = 3 and P[3]=4Then, after reversing −P[0] = 4, P[1] = 3, P[2] = 2 and P[3]=1ExampleFollowing is the C program to reverse an array −#include int ... Read More

What are the predefined functions in C language?

Bhanu Priya
Updated on 15-Mar-2021 15:01:55

11K+ Views

Functions are broadly classified into two types, which are as follows −Predefined functionsUser defined functionsPredefined (or) library functionsThese functions are already defined in the system libraries.Programmer will reuse the already present code in the system libraries to write error free code.But to use the library functions, user must be aware of syntax of the function.Example −sqrt() function is available in math.h library and its usage is −y= sqrt (x) x number must be positive eg: y = sqrt (25) then ‘y’ = 5printf ( ) present in stdio.h library.clrscr ( ) present in conio.h library.ExampleGiven below is the C program ... Read More

How to extract the split string elements in R?

Nizamuddin Siddiqui
Updated on 04-Mar-2021 08:10:17

3K+ Views

To split string vector elements, we can use strsplit function. And if we want to extract the string elements after splitting then double and single square brackets will be used. The double square bracket will extract the string vector element and the single square will extract the element after splitting. Check out the examples to understand how it works.Example1Live Demo> x1 x1Output[1] "Tutorialspoint is an E-learning platform" [2] "E-learning is important" [3] "It helps in learning and growing at a faster rate"Example> x1 x1Output[[1]] [1] "Tutorialspoint" "is" "an" "E-learning" [5] "platform" [[2]] [1] "E-learning" "is" "important" [[3]] [1] ... Read More

C Program to reverse a given number using Recursive function

Bhanu Priya
Updated on 15-Mar-2021 10:21:05

12K+ Views

"Recursive function" is something which calls itself again in the body of the function.For example, A function fact ( ), which computes the factorial of an integer ‘N’, which is the product of all whole numbers from 1 to N.fact ( ) with an argument of 1 (or) 0, the function returns 1. otherwise, it returns n*fact (n-1), this happens until ‘n’ equals 1.Fact (5) =5* fact (4)    =5*4*3* fact (3)    =5*4*3*2* fact (2)    =5*4*3*2*1 fact (1)    =5*4*3*2*1    = 120.ExampleFollowing is the C program for use of recursive function to reverse a number −#include main ... Read More

How to find the number of numerical columns in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:36:54

1K+ Views

We know that a data frame can contain any type of columns such as numerical, character, logical, factor, etc. And if a data frame contains multiple type of columns then we might want to find the number of columns for each type or of one type say numerical. For this purpose, we can use select_if function of dplyr package along with the length function as shown in the below examples.Example1Consider the below data frame −Live Demo> x1 x2 x3 x4 df1 df1Output   x1      x2          x3    x4 1  a  -0.18404831  0.1082741 2 2  b ... Read More

What are different pointer operations and problems with pointers in C language?

Bhanu Priya
Updated on 15-Mar-2021 10:13:21

3K+ Views

A pointer is a variable whose value is the address of an another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.Consider the following statement −int qty = 179;The representation of the variable in memory is as follows −You can declare a pointer as follows −Int *p;It means ‘p’ is a pointer variable that holds the address of another integer variable.Address operator (&) is used to initialize a pointer variable.For Example −int qty = 175; int *p; p= &qty;To access the value of ... Read More

Advertisements