
LANGUAGE: C++
CHALLENGE:
Write a for loop that prints, in ascending order, all the positive integers less than 200 that are divisible by both 2 and 3, separated by spaces.
SOLUTION:
for (int i=1; i<200; i++){ if ((i%2)==0 && (i%3)==0){ cout << i << " "; } }
THIS IS THE CODE FOR C:
int i;
for (i=1; i<200; i++){
if ((i%2)==0 && (i%3)==0){
printf(" %d", i);
}
}
JAVA:
for (int i = 1; i < 200; i++) {
if ((i%2)==0 && (i%3)==0) {
System.out.print(i + " ");
}
}