SlideShare a Scribd company logo
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"

More Related Content

PPTX
R Programming Language
PPTX
1_Introduction.pptx
PDF
R programmingmilano
PPTX
Ggplot2 v3
PPTX
Unit I - 1R introduction to R program.pptx
PPT
R Programming Intro
PPTX
R basics for MBA Students[1].pptx
PDF
Introduction to R programming
R Programming Language
1_Introduction.pptx
R programmingmilano
Ggplot2 v3
Unit I - 1R introduction to R program.pptx
R Programming Intro
R basics for MBA Students[1].pptx
Introduction to R programming

Similar to simple programs.docx (20)

PPTX
class.4.pptxgxdfggdxfgxfgdxbhnjgnjmjmbxg
PDF
Basics of R programming for analytics [Autosaved] (1).pdf
PDF
Unit 1 r studio programming required.pdf
PPTX
Programming with R in Big Data Analytics
PPTX
R language introduction
PDF
[1062BPY12001] Data analysis with R / week 2
PPTX
Getting Started with R
PDF
Rprogramming
PDF
Introduction to Data Science With R Lab Record
PPTX
Unit 1 financial analyticsfsddsdadsdsdsd
PPT
Loops and functions in r
PDF
R-Language-Lab-Manual-lab-1.pdf
PDF
R-Language-Lab-Manual-lab-1.pdf
PDF
R-Language-Lab-Manual-lab-1.pdf
PPTX
data analysis using R programming language
PDF
A short tutorial on r
PPTX
Data Science With R Programming Unit - II Part-1.pptx
PPTX
Data science with R Unit - II Part-1.pptx
PDF
BUilt in Functions and Simple programs in R.pdf
PDF
Introduction to r bddsil meetup
class.4.pptxgxdfggdxfgxfgdxbhnjgnjmjmbxg
Basics of R programming for analytics [Autosaved] (1).pdf
Unit 1 r studio programming required.pdf
Programming with R in Big Data Analytics
R language introduction
[1062BPY12001] Data analysis with R / week 2
Getting Started with R
Rprogramming
Introduction to Data Science With R Lab Record
Unit 1 financial analyticsfsddsdadsdsdsd
Loops and functions in r
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
data analysis using R programming language
A short tutorial on r
Data Science With R Programming Unit - II Part-1.pptx
Data science with R Unit - II Part-1.pptx
BUilt in Functions and Simple programs in R.pdf
Introduction to r bddsil meetup
Ad

More from karthikaparthasarath (20)

PPTX
KNOWLEDGE REPRESENTATION AND TYPES .pptx
PPTX
AI-KNOWLEDGE REPRESENTATION - CONTE .pptx
PPTX
AO star algorithm -Adv-Ltms-comp AI.pptx
PPTX
A star algorithm with Pseudcode AI.pptx
DOCX
List of Assignments in Power point for beginners
PDF
Software Engineering Question Bank all.pdf
PDF
MCQ cloud computing reference material.pdf
PPTX
Black-box Testing and its categories.ppt
PPTX
Software engineering -Requirement engineering.pptx
PPTX
BASIC COMPUTER ORGANIZATION unit 1.pptx
DOCX
Fundamentals of Computers MCQS.docx
DOCX
Software Engineering Question Bank.docx
PPTX
BASIC COMPUTER ORGANIZATION unit 1.pptx
PPTX
ATTACKER TECHNIQUES AND MOTIVATION.pptx
PPTX
Unit - I cyber security fundamentals part -1.pptx
PPT
Heuristic Search Techniques Unit -II.ppt
PPT
Heuristic Search Techniques Unit -II.ppt
DOCX
UNIT III Process Synchronization.docx
DOCX
Android Lab Mannual 18SUITSP5.docx
PPTX
Activity playfair cipher.pptx
KNOWLEDGE REPRESENTATION AND TYPES .pptx
AI-KNOWLEDGE REPRESENTATION - CONTE .pptx
AO star algorithm -Adv-Ltms-comp AI.pptx
A star algorithm with Pseudcode AI.pptx
List of Assignments in Power point for beginners
Software Engineering Question Bank all.pdf
MCQ cloud computing reference material.pdf
Black-box Testing and its categories.ppt
Software engineering -Requirement engineering.pptx
BASIC COMPUTER ORGANIZATION unit 1.pptx
Fundamentals of Computers MCQS.docx
Software Engineering Question Bank.docx
BASIC COMPUTER ORGANIZATION unit 1.pptx
ATTACKER TECHNIQUES AND MOTIVATION.pptx
Unit - I cyber security fundamentals part -1.pptx
Heuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.ppt
UNIT III Process Synchronization.docx
Android Lab Mannual 18SUITSP5.docx
Activity playfair cipher.pptx
Ad

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Presentation on HIE in infants and its manifestations
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Classroom Observation Tools for Teachers
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Pharma ospi slides which help in ospi learning
STATICS OF THE RIGID BODIES Hibbelers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Presentation on HIE in infants and its manifestations
Final Presentation General Medicine 03-08-2024.pptx
Classroom Observation Tools for Teachers
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Microbial diseases, their pathogenesis and prophylaxis
202450812 BayCHI UCSC-SV 20250812 v17.pptx
O7-L3 Supply Chain Operations - ICLT Program
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
VCE English Exam - Section C Student Revision Booklet
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Chinmaya Tiranga quiz Grand Finale.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Module 4: Burden of Disease Tutorial Slides S2 2025
Pharma ospi slides which help in ospi learning

simple programs.docx

  • 1. 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)) }
  • 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 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
  • 4. Enter a number: 89 [1] "89 is Odd" Output 2 Enter a number: 0 [1] "0 is Even"