how to find the summation for the odd and even numbers(from 0 to 100) save odd number in sum1 and even in sum2
117 views (last 30 days)
Show older comments
using for loop not while
Answers (1)
Raghunandan V
on 11 Mar 2019
Edited: Raghunandan V
on 12 Mar 2019
tryThis:
N=100;
Numbers = [1:1:N];
Even = Numbers((mod(Numbers,2) ==0));
Sum1 = sum(Even);
odd = Numbers((mod(Numbers,2) ==1));
sum2 = sum(odd);
2 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!