Sample R Programs
NOTE - Do not copy the whole code when you are taking input from the
user. Execute that line in which you are taking value from the user. Then
you can paste the remaining code in the R GUI editor.
1) WAP in R to find whether a given number is odd or not.
2) WAP in R to reverse a given number.
3) WAP in R to print the fibonacci series up to n
NOTE: To assign a value to a variable we can use ‘=’ instead of
‘<-’. But ‘=’ is not allowed everywhere. That is why it is better to
use ‘<-’ instead of ‘=’.
Exercise
1) WAP in R to find the area of the circle where ‘r’ is given by the
user.
2) WAP in R to convert a given temperature from celsius to fahrenheit
and vice-versa.
3) WAP in R to find the factorial of a given number.
4) WAP in R to check whether a number is prime or not.
5) WAP in R to check whether a number is palindrome or not.
6) Print the following pattern
*
**
***
****
*****
*****
****
***
**
*
*
***
*****
*******
*********