R is a free and open-source scripting language developed by Ross Ihaka
and Robert Gentleman in 1993.
R is a programming language.
R is often used for statistical computing and graphical presentation to analyze
and visualize data.
Why Use R?
 It is a great resource for data analysis, data visualization, data science
and machine learning
 It provides many statistical techniques (such as statistical tests,
classification, clustering and data reduction)
 It is easy to draw graphs in R, like pie charts, histograms, box plot,
scatter plot, etc++
 It works on different platforms (Windows, Mac, Linux)
 It is open-source and free
 It has a large community support
 It has many packages (libraries of functions) that can be used to solve
different problems
#take input from the user
num = as.integer(readline(prompt="Enter a number: "))
factorial = 1
# check is the number is negative, positive or zero
if(num < 0) {
print("Sorry, factorial does not exist for negative numbers")
} else if(num == 0) {
print("The factorial of 0 is 1")
} else {
for(i in 1:num) {
factorial = factorial * i
}
print(paste("The factorial of", num ,"is",factorial))
}
Output
Enter a number: 8
[1] "The factorial of 8 is 40320"
# R Program to find the multiplication table (from 1 to 10)
# take input from the user
num = as.integer(readline(prompt = "Enter a number: "))
# use for loop to iterate 10 times
for(i in 1:10) {
print(paste(num,'x', i, '=', num*i))
}
Output
Enter a number: 7
[1] "7 x 1 = 7"
[1] "7 x 2 = 14"
[1] "7 x 3 = 21"
[1] "7 x 4 = 28"
[1] "7 x 5 = 35"
[1] "7 x 6 = 42"
[1] "7 x 7 = 49"
[1] "7 x 8 = 56"
[1] "7 x 9 = 63"
[1] "7 x 10 = 70"
# Program to check if the input number is odd or even.
# A number is even if division by 2 give a remainder of 0.
# If remainder is 1, it is odd.
num = as.integer(readline(prompt="Enter a number: "))
if((num %% 2) == 0) {
print(paste(num,"is Even"))
} else {
print(paste(num,"is Odd"))
}
Output 1
Enter a number: 89
[1] "89 is Odd"
Output 2
Enter a number: 0
[1] "0 is Even"

simple programs.docx

  • 1.
    R is afree and open-source scripting language developed by Ross Ihaka and Robert Gentleman in 1993. R is a programming language. R is often used for statistical computing and graphical presentation to analyze and visualize data. Why Use R?  It is a great resource for data analysis, data visualization, data science and machine learning  It provides many statistical techniques (such as statistical tests, classification, clustering and data reduction)  It is easy to draw graphs in R, like pie charts, histograms, box plot, scatter plot, etc++  It works on different platforms (Windows, Mac, Linux)  It is open-source and free  It has a large community support  It has many packages (libraries of functions) that can be used to solve different problems #take input from the user num = as.integer(readline(prompt="Enter a number: ")) factorial = 1 # check is the number is negative, positive or zero if(num < 0) { print("Sorry, factorial does not exist for negative numbers") } else if(num == 0) { print("The factorial of 0 is 1") } else { for(i in 1:num) { factorial = factorial * i } print(paste("The factorial of", num ,"is",factorial)) }
  • 2.
    Output Enter a number:8 [1] "The factorial of 8 is 40320" # R Program to find the multiplication table (from 1 to 10) # take input from the user num = as.integer(readline(prompt = "Enter a number: ")) # use for loop to iterate 10 times for(i in 1:10) { print(paste(num,'x', i, '=', num*i)) } Output Enter a number: 7 [1] "7 x 1 = 7" [1] "7 x 2 = 14" [1] "7 x 3 = 21" [1] "7 x 4 = 28"
  • 3.
    [1] "7 x5 = 35" [1] "7 x 6 = 42" [1] "7 x 7 = 49" [1] "7 x 8 = 56" [1] "7 x 9 = 63" [1] "7 x 10 = 70" # Program to check if the input number is odd or even. # A number is even if division by 2 give a remainder of 0. # If remainder is 1, it is odd. num = as.integer(readline(prompt="Enter a number: ")) if((num %% 2) == 0) { print(paste(num,"is Even")) } else { print(paste(num,"is Odd")) } Output 1
  • 4.
    Enter a number:89 [1] "89 is Odd" Output 2 Enter a number: 0 [1] "0 is Even"