5.6: the for Loop: 10808

Question

Given an  int variable  i that has already been declared, write a  for loop  that prints the integers 0 through 39, separated by spaces. Use no variables other than  i .

Solution
for (i=0; i<=39; i++)
    cout << i << '\n';

1 comment:

  1. This also works:
    for (i=-1;i<39; i++)
    cout << i+1 << "\n";

    ReplyDelete