Exercícios do Capítulo 2
a = 12 ; b = 11 ;c = 10
if(a + b > c && a + c > b && c + b > a){
if(a == b && b == c) {
print("O triângulo é equilátero")
}
else if(a == b && b != c || a == c && c != b|| b == c && b != a){
print("O triângulo é isósceles")
}
else{
print("O triângulo é escaleno")
}
} else{
print("Não é possível formar um triângulo")
}
## [1] "O triângulo é escaleno"
mult_3 = c()
for(passo in 1:100){
mult_3 = c(mult_3, passo * 3)
}
mult_3
## [1] 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54
## [19] 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108
## [37] 111 114 117 120 123 126 129 132 135 138 141 144 147 150 153 156 159 162
## [55] 165 168 171 174 177 180 183 186 189 192 195 198 201 204 207 210 213 216
## [73] 219 222 225 228 231 234 237 240 243 246 249 252 255 258 261 264 267 270
## [91] 273 276 279 282 285 288 291 294 297 300
mult_3 = c()
for(passo in 1:100){
aux = passo * 3
if(aux < 100){
mult_3 = c(mult_3, aux)
}
}
mult_3
## [1] 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75
## [26] 78 81 84 87 90 93 96 99
impares = c()
for(passo in 1:200){
resto = passo%%2
if(resto == 1){
impares = c(impares, passo)
}
}
impares
## [1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35
## [19] 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71
## [37] 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107
## [55] 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143
## [73] 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179
## [91] 181 183 185 187 189 191 193 195 197 199
mult_3 = c()
passo = 1
while(length(mult_3) < 100){
mult_3 = c(mult_3, passo * 3)
passo = passo + 1
}
mult_3
## [1] 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54
## [19] 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108
## [37] 111 114 117 120 123 126 129 132 135 138 141 144 147 150 153 156 159 162
## [55] 165 168 171 174 177 180 183 186 189 192 195 198 201 204 207 210 213 216
## [73] 219 222 225 228 231 234 237 240 243 246 249 252 255 258 261 264 267 270
## [91] 273 276 279 282 285 288 291 294 297 300
#ou
mult_3 = c()
passo = 1
repeat{
if(passo > 100)
break
mult_3 = c(mult_3, passo * 3)
passo = passo + 1
}
mult_3
## [1] 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54
## [19] 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108
## [37] 111 114 117 120 123 126 129 132 135 138 141 144 147 150 153 156 159 162
## [55] 165 168 171 174 177 180 183 186 189 192 195 198 201 204 207 210 213 216
## [73] 219 222 225 228 231 234 237 240 243 246 249 252 255 258 261 264 267 270
## [91] 273 276 279 282 285 288 291 294 297 300
mult_3 = c()
passo = 1
while(passo*3 < 100){
mult_3 = c(mult_3, passo*3)
passo = passo + 1
}
mult_3
## [1] 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75
## [26] 78 81 84 87 90 93 96 99
#ou
mult_3 = c()
passo = 1
repeat{
if(passo*3 >= 100)
break
mult_3 = c(mult_3, passo*3)
passo = passo + 1
}
mult_3
## [1] 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75
## [26] 78 81 84 87 90 93 96 99
impares = c()
passo = 1
while(length(impares) < 100){
num = passo%%2
if(num == 1){
impares = c(impares, passo)
}
passo = passo + 1
}
impares
## [1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35
## [19] 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71
## [37] 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107
## [55] 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143
## [73] 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179
## [91] 181 183 185 187 189 191 193 195 197 199
#ou
impares = c()
passo = 0
repeat{
if(length(impares) == 100)
break
impares = c(impares, 2*passo+1)
passo = passo + 1
}
impares
## [1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35
## [19] 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71
## [37] 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107
## [55] 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143
## [73] 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179
## [91] 181 183 185 187 189 191 193 195 197 199
matriz = matrix(0, nrow = 10, ncol = 10)
for(i in 1:10){
matriz[1,i] = 1
}
matriz
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1 1 1 1 1 1 1 1 1 1
## [2,] 0 0 0 0 0 0 0 0 0 0
## [3,] 0 0 0 0 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 0 0 0 0
## [5,] 0 0 0 0 0 0 0 0 0 0
## [6,] 0 0 0 0 0 0 0 0 0 0
## [7,] 0 0 0 0 0 0 0 0 0 0
## [8,] 0 0 0 0 0 0 0 0 0 0
## [9,] 0 0 0 0 0 0 0 0 0 0
## [10,] 0 0 0 0 0 0 0 0 0 0
matriz = matrix(0, nrow = 10, ncol = 10)
for(i in 1:10){
for(j in 1:10){
matriz[i,j] = i
}
}
matriz
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1 1 1 1 1 1 1 1 1 1
## [2,] 2 2 2 2 2 2 2 2 2 2
## [3,] 3 3 3 3 3 3 3 3 3 3
## [4,] 4 4 4 4 4 4 4 4 4 4
## [5,] 5 5 5 5 5 5 5 5 5 5
## [6,] 6 6 6 6 6 6 6 6 6 6
## [7,] 7 7 7 7 7 7 7 7 7 7
## [8,] 8 8 8 8 8 8 8 8 8 8
## [9,] 9 9 9 9 9 9 9 9 9 9
## [10,] 10 10 10 10 10 10 10 10 10 10
matriz = matrix(0, nrow = 100, ncol = 100)
for(i in 1:100){
for(j in 1:100){
matriz[i,j] = j
}
}
matriz[1:10,1:10]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1 2 3 4 5 6 7 8 9 10
## [2,] 1 2 3 4 5 6 7 8 9 10
## [3,] 1 2 3 4 5 6 7 8 9 10
## [4,] 1 2 3 4 5 6 7 8 9 10
## [5,] 1 2 3 4 5 6 7 8 9 10
## [6,] 1 2 3 4 5 6 7 8 9 10
## [7,] 1 2 3 4 5 6 7 8 9 10
## [8,] 1 2 3 4 5 6 7 8 9 10
## [9,] 1 2 3 4 5 6 7 8 9 10
## [10,] 1 2 3 4 5 6 7 8 9 10
matriz[91:100,91:100]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 91 92 93 94 95 96 97 98 99 100
## [2,] 91 92 93 94 95 96 97 98 99 100
## [3,] 91 92 93 94 95 96 97 98 99 100
## [4,] 91 92 93 94 95 96 97 98 99 100
## [5,] 91 92 93 94 95 96 97 98 99 100
## [6,] 91 92 93 94 95 96 97 98 99 100
## [7,] 91 92 93 94 95 96 97 98 99 100
## [8,] 91 92 93 94 95 96 97 98 99 100
## [9,] 91 92 93 94 95 96 97 98 99 100
## [10,] 91 92 93 94 95 96 97 98 99 100
matriz = matrix(0, nrow = 100, ncol = 100)
for(i in 1:100){
for(j in 1:100){
if(i%%2 == 0){
matriz[i,j] = 2
}else{
matriz[i,j] = 1
}
}
}
matriz[1:10,1:10]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1 1 1 1 1 1 1 1 1 1
## [2,] 2 2 2 2 2 2 2 2 2 2
## [3,] 1 1 1 1 1 1 1 1 1 1
## [4,] 2 2 2 2 2 2 2 2 2 2
## [5,] 1 1 1 1 1 1 1 1 1 1
## [6,] 2 2 2 2 2 2 2 2 2 2
## [7,] 1 1 1 1 1 1 1 1 1 1
## [8,] 2 2 2 2 2 2 2 2 2 2
## [9,] 1 1 1 1 1 1 1 1 1 1
## [10,] 2 2 2 2 2 2 2 2 2 2
matriz[91:100,91:100]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1 1 1 1 1 1 1 1 1 1
## [2,] 2 2 2 2 2 2 2 2 2 2
## [3,] 1 1 1 1 1 1 1 1 1 1
## [4,] 2 2 2 2 2 2 2 2 2 2
## [5,] 1 1 1 1 1 1 1 1 1 1
## [6,] 2 2 2 2 2 2 2 2 2 2
## [7,] 1 1 1 1 1 1 1 1 1 1
## [8,] 2 2 2 2 2 2 2 2 2 2
## [9,] 1 1 1 1 1 1 1 1 1 1
## [10,] 2 2 2 2 2 2 2 2 2 2
matriz = matrix(0, nrow = 100, ncol = 100)
for(i in 1:100){
matriz[i,i] = i
}
matriz[1:10,1:10]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1 0 0 0 0 0 0 0 0 0
## [2,] 0 2 0 0 0 0 0 0 0 0
## [3,] 0 0 3 0 0 0 0 0 0 0
## [4,] 0 0 0 4 0 0 0 0 0 0
## [5,] 0 0 0 0 5 0 0 0 0 0
## [6,] 0 0 0 0 0 6 0 0 0 0
## [7,] 0 0 0 0 0 0 7 0 0 0
## [8,] 0 0 0 0 0 0 0 8 0 0
## [9,] 0 0 0 0 0 0 0 0 9 0
## [10,] 0 0 0 0 0 0 0 0 0 10
matriz[91:100,91:100]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 91 0 0 0 0 0 0 0 0 0
## [2,] 0 92 0 0 0 0 0 0 0 0
## [3,] 0 0 93 0 0 0 0 0 0 0
## [4,] 0 0 0 94 0 0 0 0 0 0
## [5,] 0 0 0 0 95 0 0 0 0 0
## [6,] 0 0 0 0 0 96 0 0 0 0
## [7,] 0 0 0 0 0 0 97 0 0 0
## [8,] 0 0 0 0 0 0 0 98 0 0
## [9,] 0 0 0 0 0 0 0 0 99 0
## [10,] 0 0 0 0 0 0 0 0 0 100
matriz = matrix(0, nrow = 100, ncol = 100)
for(i in 1:100){
matriz[i,i] = 101 - i
}
matriz[1:10,1:10]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 100 0 0 0 0 0 0 0 0 0
## [2,] 0 99 0 0 0 0 0 0 0 0
## [3,] 0 0 98 0 0 0 0 0 0 0
## [4,] 0 0 0 97 0 0 0 0 0 0
## [5,] 0 0 0 0 96 0 0 0 0 0
## [6,] 0 0 0 0 0 95 0 0 0 0
## [7,] 0 0 0 0 0 0 94 0 0 0
## [8,] 0 0 0 0 0 0 0 93 0 0
## [9,] 0 0 0 0 0 0 0 0 92 0
## [10,] 0 0 0 0 0 0 0 0 0 91
matriz[91:100,91:100]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 10 0 0 0 0 0 0 0 0 0
## [2,] 0 9 0 0 0 0 0 0 0 0
## [3,] 0 0 8 0 0 0 0 0 0 0
## [4,] 0 0 0 7 0 0 0 0 0 0
## [5,] 0 0 0 0 6 0 0 0 0 0
## [6,] 0 0 0 0 0 5 0 0 0 0
## [7,] 0 0 0 0 0 0 4 0 0 0
## [8,] 0 0 0 0 0 0 0 3 0 0
## [9,] 0 0 0 0 0 0 0 0 2 0
## [10,] 0 0 0 0 0 0 0 0 0 1
L1 = list()
for(i in 1:10){
L1[[i]] = i
}
L1
## [[1]]
## [1] 1
##
## [[2]]
## [1] 2
##
## [[3]]
## [1] 3
##
## [[4]]
## [1] 4
##
## [[5]]
## [1] 5
##
## [[6]]
## [1] 6
##
## [[7]]
## [1] 7
##
## [[8]]
## [1] 8
##
## [[9]]
## [1] 9
##
## [[10]]
## [1] 10
L2 = list()
for(i in 1:10){
aux = c()
for(j in 1:i){
aux = c(aux,1)
}
L2[[i]] = aux
}
L2
## [[1]]
## [1] 1
##
## [[2]]
## [1] 1 1
##
## [[3]]
## [1] 1 1 1
##
## [[4]]
## [1] 1 1 1 1
##
## [[5]]
## [1] 1 1 1 1 1
##
## [[6]]
## [1] 1 1 1 1 1 1
##
## [[7]]
## [1] 1 1 1 1 1 1 1
##
## [[8]]
## [1] 1 1 1 1 1 1 1 1
##
## [[9]]
## [1] 1 1 1 1 1 1 1 1 1
##
## [[10]]
## [1] 1 1 1 1 1 1 1 1 1 1
L3 = list()
for(i in 1:10){
aux = c()
for(j in 1:10){
aux = c(aux,i*j)
}
L3[[i]] = aux
}
L3
## [[1]]
## [1] 1 2 3 4 5 6 7 8 9 10
##
## [[2]]
## [1] 2 4 6 8 10 12 14 16 18 20
##
## [[3]]
## [1] 3 6 9 12 15 18 21 24 27 30
##
## [[4]]
## [1] 4 8 12 16 20 24 28 32 36 40
##
## [[5]]
## [1] 5 10 15 20 25 30 35 40 45 50
##
## [[6]]
## [1] 6 12 18 24 30 36 42 48 54 60
##
## [[7]]
## [1] 7 14 21 28 35 42 49 56 63 70
##
## [[8]]
## [1] 8 16 24 32 40 48 56 64 72 80
##
## [[9]]
## [1] 9 18 27 36 45 54 63 72 81 90
##
## [[10]]
## [1] 10 20 30 40 50 60 70 80 90 100
L4 = list()
for(i in 1:10){
aux = c()
for(j in 1:i){
aux = c(aux,j*2)
}
L4[[i]] = aux
}
L4
## [[1]]
## [1] 2
##
## [[2]]
## [1] 2 4
##
## [[3]]
## [1] 2 4 6
##
## [[4]]
## [1] 2 4 6 8
##
## [[5]]
## [1] 2 4 6 8 10
##
## [[6]]
## [1] 2 4 6 8 10 12
##
## [[7]]
## [1] 2 4 6 8 10 12 14
##
## [[8]]
## [1] 2 4 6 8 10 12 14 16
##
## [[9]]
## [1] 2 4 6 8 10 12 14 16 18
##
## [[10]]
## [1] 2 4 6 8 10 12 14 16 18 20
L5 = list()
for(i in 1:10){
matriz = matrix(0, nrow = i, ncol = i)
for(j in 1:i){
matriz[j,j] = 1
}
L5[[i]] = matriz
}
L5
## [[1]]
## [,1]
## [1,] 1
##
## [[2]]
## [,1] [,2]
## [1,] 1 0
## [2,] 0 1
##
## [[3]]
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 0 1 0
## [3,] 0 0 1
##
## [[4]]
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] 0 1 0 0
## [3,] 0 0 1 0
## [4,] 0 0 0 1
##
## [[5]]
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 0 0
## [2,] 0 1 0 0 0
## [3,] 0 0 1 0 0
## [4,] 0 0 0 1 0
## [5,] 0 0 0 0 1
##
## [[6]]
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 1 0 0 0 0 0
## [2,] 0 1 0 0 0 0
## [3,] 0 0 1 0 0 0
## [4,] 0 0 0 1 0 0
## [5,] 0 0 0 0 1 0
## [6,] 0 0 0 0 0 1
##
## [[7]]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 1 0 0 0 0 0 0
## [2,] 0 1 0 0 0 0 0
## [3,] 0 0 1 0 0 0 0
## [4,] 0 0 0 1 0 0 0
## [5,] 0 0 0 0 1 0 0
## [6,] 0 0 0 0 0 1 0
## [7,] 0 0 0 0 0 0 1
##
## [[8]]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,] 1 0 0 0 0 0 0 0
## [2,] 0 1 0 0 0 0 0 0
## [3,] 0 0 1 0 0 0 0 0
## [4,] 0 0 0 1 0 0 0 0
## [5,] 0 0 0 0 1 0 0 0
## [6,] 0 0 0 0 0 1 0 0
## [7,] 0 0 0 0 0 0 1 0
## [8,] 0 0 0 0 0 0 0 1
##
## [[9]]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## [1,] 1 0 0 0 0 0 0 0 0
## [2,] 0 1 0 0 0 0 0 0 0
## [3,] 0 0 1 0 0 0 0 0 0
## [4,] 0 0 0 1 0 0 0 0 0
## [5,] 0 0 0 0 1 0 0 0 0
## [6,] 0 0 0 0 0 1 0 0 0
## [7,] 0 0 0 0 0 0 1 0 0
## [8,] 0 0 0 0 0 0 0 1 0
## [9,] 0 0 0 0 0 0 0 0 1
##
## [[10]]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1 0 0 0 0 0 0 0 0 0
## [2,] 0 1 0 0 0 0 0 0 0 0
## [3,] 0 0 1 0 0 0 0 0 0 0
## [4,] 0 0 0 1 0 0 0 0 0 0
## [5,] 0 0 0 0 1 0 0 0 0 0
## [6,] 0 0 0 0 0 1 0 0 0 0
## [7,] 0 0 0 0 0 0 1 0 0 0
## [8,] 0 0 0 0 0 0 0 1 0 0
## [9,] 0 0 0 0 0 0 0 0 1 0
## [10,] 0 0 0 0 0 0 0 0 0 1
soma = 0
for(elemento in L1){
soma = soma + elemento
}
soma
## [1] 55
soma = c()
for(elemento in L3){
aux = 0
for(numero in elemento){
aux = aux + numero
}
soma = c(soma, aux)
}
soma
## [1] 55 110 165 220 275 330 385 440 495 550
soma = c()
for(elemento in L4){
aux = 0
for(numero in elemento){
aux = aux + numero
}
soma = c(soma, aux)
}
soma
## [1] 2 6 12 20 30 42 56 72 90 110
v = c()
for(elemento in L4){
soma_pos = 0
for(numero in elemento){
soma_pos = soma_pos + numero
}
if(soma_pos%%5 == 0){
v = c(v, paste(soma_pos,"é múltiplo de 5"))
}else{
v = c(v, paste(soma_pos,"não é múltiplo de 5"))
}
}
v
## [1] "2 não é múltiplo de 5" "6 não é múltiplo de 5" "12 não é múltiplo de 5"
## [4] "20 é múltiplo de 5" "30 é múltiplo de 5" "42 não é múltiplo de 5"
## [7] "56 não é múltiplo de 5" "72 não é múltiplo de 5" "90 é múltiplo de 5"
## [10] "110 é múltiplo de 5"
qtd_m5 = 0
for(elemento in soma){
if(elemento%%5 == 0){
qtd_m5 = qtd_m5 + 1
}
}
qtd_m5
## [1] 4
x0 = 2
r = 3
y = c(x0)
for(passo in 2:100){
y = c(y, y[passo-1] + r)
}
y
## [1] 2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53
## [19] 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107
## [37] 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161
## [55] 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215
## [73] 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269
## [91] 272 275 278 281 284 287 290 293 296 299
formula_soma_pa = (y[1] + y[35])*35/2
soma_r = 0
for(numero in y[1:35]){
soma_r = soma_r + numero
}
soma_r
## [1] 1855
soma_r == formula_soma_pa
## [1] TRUE
qtd_mult_4 = 0
for(elemento in y){
if(elemento%%4 == 0){
qtd_mult_4 = qtd_mult_4 + 1
}
}
qtd_mult_4
## [1] 25
qtd_mult_4_5 = 0
for(elemento in y){
if(elemento%%4 == 0 && elemento%%5 == 0){
qtd_mult_4_5 = qtd_mult_4_5 + 1
}
}
qtd_mult_4_5
## [1] 5
qtd_mult_4_ou_5 = 0
for(elemento in y){
if(elemento%%4 == 0 || elemento%%5 == 0){
qtd_mult_4_ou_5 = qtd_mult_4_ou_5 + 1
}
}
qtd_mult_4_ou_5
## [1] 40
x = c()
for(elemento in y){
if(elemento%%2 == 0){
x = c(x, elemento)
}
else{
x = c(x,0)
}
}
x
## [1] 2 0 8 0 14 0 20 0 26 0 32 0 38 0 44 0 50 0
## [19] 56 0 62 0 68 0 74 0 80 0 86 0 92 0 98 0 104 0
## [37] 110 0 116 0 122 0 128 0 134 0 140 0 146 0 152 0 158 0
## [55] 164 0 170 0 176 0 182 0 188 0 194 0 200 0 206 0 212 0
## [73] 218 0 224 0 230 0 236 0 242 0 248 0 254 0 260 0 266 0
## [91] 272 0 278 0 284 0 290 0 296 0
fib_12 = c(1,1)
while(length(fib_12) < 12){
qtd_elementos = length(fib_12)
fib_12 = c(fib_12, fib_12[qtd_elementos] + fib_12[qtd_elementos-1])
}
fib_12
## [1] 1 1 2 3 5 8 13 21 34 55 89 144
fib_300 = c(1,1)
qtd_elementos = length(fib_300)
soma = fib_300[qtd_elementos] + fib_300[qtd_elementos-1]
while(soma < 300){
fib_300 = c(fib_300, soma)
qtd_elementos = length(fib_300)
soma = fib_300[qtd_elementos] + fib_300[qtd_elementos-1]
}
fib_300
## [1] 1 1 2 3 5 8 13 21 34 55 89 144 233
fib = c(1,1)
soma = 2
qtd = 2
while(soma < 1000000){
qtd = qtd + 1
fib = c(fib[2], soma)
qtd_elementos = length(fib)
soma = 0
for(numero in fib){
soma = soma + numero
}
}
qtd
## [1] 30