Programming Code Examples

R Program to Take Input From User

Here is an example of an R program that prompts the user to enter two numbers and then adds them: # read the numbers from the user x <- as.numeric(readline(prompt = "Enter the first number: ")) y <- as...

R Program to Add Two Vectors

Example 1, Here is an example of an R program that adds two vectors and prints the result: # define the vectors v1 <- c(1, 2, 3, 4) v2 <- c(5, 6, 7, 8) # add the vectors v3 <- v1 + v2 # print the result...

How to Work with Swing Operations in Java

In this article we will look at some of the swing controls available in javax.swing package along with sample Java code for each control. Swing is a collection of libraries for creating graphical user interfaces (GUIs)...

Python Tutorial with Exercises

For beginner Python programmers, the main ones are that the print statement of Python 2.x is now a printfunction in Python 3, the raw_input function in Python 2.x is replaced by the input function in Python 3, and an...

C Function Pointer in a While Loop Examples

What is Pointer in C In C, a pointer is a variable that stores the memory address of another variable. Pointers are used to store the addresses of dynamically allocated memory, to pass arguments to functions by...

How To Use bash For Loop In One Line

In bash, you can use a for loop in a single line by using the following syntax: for variable in list; do command1; command2; done 123  for variable in list; do command1; command2; done  Here’s an example...

Write AC code while loop

This is an example of an infinite while loop in C. The condition inside the parenthesis, in this case true, will always evaluate to true, causing the code inside the loop to run indefinitely. Make sure to include a way...

Sum Digits of Two-Digit Integers

To solve this problem, we can use the modulo operator (%) and integer division (//) to separate the digits of the two-digit integer. Here’s some example code that demonstrates how to do this in Python: def...

How to Reverse an Array in-place using Pointers

A pointer is a variable that stores a memory address, which can be used to access and manipulate the value stored at that memory location. Pointers allow for more efficient memory management and can be used to create...