2 ms·
Example Problem: Calculate the sum of the first N natural numbers. Declarative: N(N+1)/2 Imperative: for(int sum=0, int i=1; i<=N; i++) {sum = sum+i;}
by rramadass 4y ago
Example Problem: Calculate the sum of the first N natural numbers.
Declarative: N(N+1)/2
Imperative: for(int sum=0, int i=1; i<=N; i++) {sum = sum+i;}