What is my two logic errors? - TechRepublic
General discussion
June 27, 2001 at 02:23 AM
barrylj

What is my two logic errors?

by barrylj . Updated 25 years ago

// Total the square of every 3rd number from 1 to 25
// Sum every 4th number from 1 to 25

int num;
int total_squared = 0;
int total_summed = 0;

for (num = 1; num < 25; num++) if (num % 4) total_squared = total_squared + (num * num); if (num % 3) total_summed = total_summed + num;

This discussion is locked

All Comments