write an algorithm to calculate even numbers between 10 and 250
1 Set count equal 0
2 Set num equal 10
3 If num is even add 1 to count
4 Add 1 to num
5 If num is less or equal 250 go to step 3
6 Return count
The realisation of the algorithm on C++:
#include <iostream>
using namespace std;
int main() {
int count=0;
for (int num=20; num<=250; num++) {
if (num%2 == 0) {
count++;
}
}
cout << count;
return 0;
}
Comments
Leave a comment