B.Sc Computer Science
R Programming - Lab
Bharathiar University
R Expressions and Data Structures
Program 1 {a}- Write a R program to perform some arithmetic expressions.
SOURCE CODE:
# R Program for Expressions
# This program demonstrates basic arithmetic expressions in R.
# Define variables
a <- 10
b <- 5
# Calculate and print the results of different expressions
sum <- a + b
difference <- a - b
product <- a * b
quotient <- a / b
# Print the results
print(paste("Sum:",sum))
print(paste("Difference:", difference))
print(paste("Product:", product))
print(paste("Quotient:", quotient))
Sample OUTPUT:
# R Program for Expressions
> # This program demonstrates basic arithmetic expressions in R.
>
> # Define variables
> a <- 10
> b <- 5
>
> # Calculate and print the results of different expressions
> sum <- a + b
> difference <- a - b
> product <- a * b
> quotient <- a / b
>
> # Print the results
> print(paste("Sum:",sum))
[1] "Sum: 15"
> print(paste("Difference:", difference))
[1] "Difference: 5"
> print(paste("Product:", product))
[1] "Product: 50"
> print(paste("Quotient:", quotient))
[1] "Quotient: 2"
| |
|
No comments:
Post a Comment