Adding number in a sequence
2 次查看(过去 30 天)
显示 更早的评论
How do i make a code,where I have to add the previous numbers to next numbers in a sequence. I used a for loop
for jj=0:13
x=jj
this code gives me the value of 0 to 13.right?
but I need to add all the terms with a previous term . what can I do?
3 个评论
Guillaume
2019-9-21
I have absolutely no idea what you're attempting to do with that code. It doesn't make any sense.
i only ge6t the name of the file on the command window ,,no output except for the array of n in 1st line
That would be because the while condition is not true to start with. So the code inside the while is never executed and only the first line has any effect.
Note that isprime return either 0 or 1. So if n is scalar, n == isprime(n) will definitively be false for any n different from 0 or 1. And since isprime is 0, the only n value for which n == isprime(n) is true is n = 0. But also note that your n is a vector.
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!