This repository was archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3.Operators.r
More file actions
71 lines (63 loc) · 1.38 KB
/
3.Operators.r
File metadata and controls
71 lines (63 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Experiment - 3
# Aim: Write an R Program to demonstrate working with operators.
# Source code:
Operators = function( x, y )
{
# Arithmetic Operator
cat("\nArithmetic on",x,",",y,"are as follows : \n")
cat(x,"+",y,"=",(x+y),"\n")
cat(x,"-",y,"=",(x-y),"\n")
cat(x,"*",y,"=",(x*y),"\n")
cat(x,"/",y,"=",(x/y),"\n")
cat(x,"%",y,"=",(x%%y),"\n")
# Relational Operator
cat("\nRelation Between",x,"and",y,": ")
if( x == y )
{
cat(x,"and",y,"are equal numbers.\n")
}
else if( x > y )
{
cat(x,"is greater than",y,".\n")
}
else
{
cat(x,"is lesser than",y,".\n")
}
# Logical Operator
cat("\nLogical Relation between",x,"and",y,": ")
if( x > 0 && y > 0 )
{
cat("Both",x,"and",y,"are positive.\n")
}
else if( x < 0 || y < 0 )
{
cat("Either of",x,"or",y,"is a negative number.\n")
}
# Assignment Operator
cat("\nAssigning value '4' to 'x' : ")
x=4
cat("x =",x)
}
a=as.numeric(readline("\nEnter a value : "))
b=as.numeric(readline("Enter another value : "))
Operators(a,b)
# Input :
# 1
# 4
# Output :
# Enter a value : 1
# Enter another value : 4
#
# Arithmetic on 1 , 4 are as follows :
# 1 + 4 = 5
# 1 - 4 = -3
# 1 * 4 = 4
# 1 / 4 = 0.25
# 1 % 4 = 1
#
# Relation Between 1 and 4 : 1 is lesser than 4 .
#
# Logical Relation between 1 and 4 : Both 1 and 4 are positive.
#
# Assigning value '4' to 'x' : x = 4