Programming Articles

Page 157 of 2544

How to select positive values in an R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

We know that positive values are greater thandf1$x[which(df1$x>0)]Example1set.seed(254) x

Read More

Given an example of C pointer addition and subtraction

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 3K+ Views

Pointers have many but easy concepts and they are very important to C programming.Two of the arithmetic pointer concepts are explained below, which are C pointer addition and subtraction respectively.C pointer additionC pointer addition refers to adding a value to the pointer variable.The formula is as follows −new_address= current_address + (number * size_of(data type))ExampleFollowing is the C program for C pointer addition −#include int main(){    int num=500;    int *ptr;//pointer to int    ptr=#//stores the address of number variable    printf("add of ptr is %u ", ptr);    ptr=ptr+7; //adding 7 to pointer variable    printf("after adding add of ...

Read More

Write a Golang program to search an element in an array

Kiran P
Kiran P
Updated on 11-Mar-2026 447 Views

Definition: A number is that is greater than 2 and divisible only by itself and 1.Examples: Prime numbers are 2, 3, 5, 7, 11, 13, 113, 119, ..., etc.Approach to solve this problemStep 1: Find square root of the given number, sq_root = √numStep 2: If the given number is divisible by a number that belongs to [2, sq_root], then print “Non Prime Number”Step 3: If not divisible by any number, then print “Prime Number”Programpackage main import (    "fmt"    "math" ) func checkPrimeNumber(num int) {    if num < 2 {       fmt.Println("Number must be greater than 2.")       return    }    sq_root := int(math.Sqrt(float64(num)))    for i:=2; i

Read More

How to save a plot in pdf in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

To save a plot in pdf, we can use the pdf function in base R. For example, if we want to save a plot with the name PDF then it can be done using the below command −pdf("PDF.pdf")After this we can create the plot and use dev.off().Examplepdf("pdfExample.pdf") plot(1:10)OutputExampledev.off()OutputTo check where it is saved, find the working directory using getwd().

Read More

Accessing variables of Int and Float without initializing in C

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 2K+ Views

ProblemDeclare int and float variables without initializing and try to print their values in C language. Explain what will happen.SolutionIf a variable is declared but not initialized or uninitialized and if those variables are trying to print, then, it will return 0 or some garbage value.Whenever we declare a variable, a location is allocated to that variable. The only thing is with the help of initialization, we are trying to occupy the memory location which is already allotted while declaration.But in the below program, we are not initializing the values in the memory locations which are reserved. But, by default, ...

Read More

Write a Golang program to find the factorial of a given number (Using Recursion)

Kiran P
Kiran P
Updated on 11-Mar-2026 3K+ Views

ExamplesFactorial of 5 = 5*4*3*2*1 = 120Factorial of 10 = 10*9*8*7*6*5*4*3*2*1 =Approach to solve this problemStep 1: Define a function that accepts a number (greater than 0), type is int.Step 2: If the number is 1, then return 1.Step 3: Otherwise, return num*function(num-1).Programpackage main import "fmt" func factorial(num int) int{    if num == 1 || num == 0{       return num    }    return num * factorial(num-1) } func main(){    fmt.Println(factorial(3))    fmt.Println(factorial(4))    fmt.Println(factorial(5)) }Output6 24 120

Read More

Write a Golang program to swap two numbers without using a third variable

Kiran P
Kiran P
Updated on 11-Mar-2026 1K+ Views

Approach to solve this problemStep 1: Define a function that accepts two numbers, type is int.Step 2: Find b = a + b;Step 3: Then a = b – a and b = b – aProgrampackage main import "fmt" func swap(a, b int){    fmt.Printf("Before swapping, numbers are %d and %d", a, b)    b = a + b    a = b - a    b = b - a    fmt.Printf("After swapping, numbers are %d and %d", a, b) } func main(){    swap(23, 45)    swap(56, 100) }OutputBefore swapping, numbers are 23 and 45 After swapping, numbers are 45 and 23 Before swapping, numbers are 56 and 100 After swapping, numbers are 100 and 56

Read More

Explain the variable declaration, initialization and assignment in C language

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 12K+ Views

The main purpose of variables is to store data in memory. Unlike constants, it will not change during the program execution. However, its value may be changed during execution.The variable declaration indicates that the operating system is going to reserve a piece of memory with that variable name.Variable declarationThe syntax for variable declaration is as follows −type variable_name;ortype variable_name, variable_name, variable_name;For example, iInt a, b; float c; double d;Here, a, b, c, d are variables. The int, float, double are the data types.Variable initializationThe syntax for variable initialization is as follows −data type variablename=value;For example, int width, height=20; char letter='R'; ...

Read More

Can we override default methods in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 8K+ Views

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since Java8 static methods and default methods are introduced in interfaces. Unlike other abstract methods these are the methods can have a default implementation. If you have default method in an interface, it is not mandatory to override (provide body) it in the classes that are already implementing this interface.In short, you can access the default methods of an interface using the objects of the implementing classes.Exampleinterface MyInterface{      public static int num = 100;    public default void ...

Read More

How to create the stacked bar plot using ggplot2 in R with labels on the plot?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

The creation of stacked bar plot using ggplot2 can be done with the help of position="stack" argument inside geom_bar function. If we want to create the stacked bar plot then geom_text function will be used with the same position argument and the aes to define the labels as shown in the below example.Exampledf

Read More
Showing 1561–1570 of 25,433 articles
« Prev 1 155 156 157 158 159 2544 Next »
Advertisements