x<-0 #initialising the function x
for(i in 0:49) #introducing “for” loop
- {x[i]=(i+(i+1)) #quantifying the parameter x
- print(x[i]) #instructing R to print x
- }
numeric(0)
[1] 3
[1] 5
[1] 7
[1] 9
[1] 11
[1] 13
[1] 15
[1] 17
[1] 19
[1] 21
[1] 23
[1] 25
[1] 27
[1] 29
[1] 31
[1] 33
[1] 35
[1] 37
[1] 39
[1] 41
[1] 43
[1] 45
[1] 47
[1] 49
[1] 51
[1] 53
[1] 55
[1] 57
[1] 59
[1] 61
[1] 63
[1] 65
[1] 67
[1] 69
[1] 71
[1] 73
[1] 75
[1] 77
[1] 79
[1] 81
[1] 83
[1] 85
[1] 87
[1] 89
[1] 91
[1] 93
[1] 95
[1] 97
[1] 99
y<-0 #initialising the function y
for(i in 0:49) #introducing “for” loop - {y[i]=(i+(i+1)) #quantifying the parameter y
- print(y[i]) #instructing R to print y
- }
numeric(0)
[1] 3
[1] 5
[1] 7
[1] 9
[1] 11
[1] 13
[1] 15
[1] 17
[1] 19
[1] 21
[1] 23
[1] 25
[1] 27
[1] 29
[1] 31
[1] 33
[1] 35
[1] 37
[1] 39
[1] 41
[1] 43
[1] 45
[1] 47
[1] 49
[1] 51
[1] 53
[1] 55
[1] 57
[1] 59
[1] 61
[1] 63
[1] 65
[1] 67
[1] 69
[1] 71
[1] 73
[1] 75
[1] 77
[1] 79
[1] 81
[1] 83
[1] 85
[1] 87
[1] 89
[1] 91
[1] 93
[1] 95
[1] 97
[1] 99
m<-sum(print(y[i]),print(x[i]))
[1] 99
[1] 99
m
[1] 198
Pseudocode
Create two functions in R for example say y=0 and x=0
Introduce “for” loops in R for example in our case we are going to say “for variable i in variables 0-49
Then introduce an open curly brackets
Then identify x to equal to sum of variable i plus variable i+1 to get all the odd numbers between 1 to 100
The next step is to print x then close the curly bracket
Introduce new “for” loops “for variable i in variables 0-49
Introduce an open curly brackets
Then identify y to equal to sum of variable i plus variable i+2 to get all the even numbers between 1 to 100
The next step is to print y then close the curly bracket
The final step is to get the sum of total printed x and printed y, where we use the function sum to execute.
R code
x<-0 #initialising the function x
for(i in 0:49) #introducing “for” loop
{x[i]=(i+(i+1)) #quantifying the parameter x
print(x[i]) #instructing R to print x
}
y<-0 #initialising the function y
for(i in 0:49) #introducing “for” loop
{y[i]=(i+(i+1)) #quantifying the parameter y
print(y[i]) #instructing R to print y
}
m<-sum(print(y[i]),print(x[i]))
m