- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// break (P.115)
#include <iostream>
int main()
{
int sum = 0;
int i, j;
for (i=1; i<5; i++)
for (j=i; j<10; j++)
{
sum += j;
if (j == i*2)
break;
}
std::cout << sum << std::endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Conditional Operator (P.103)
#include <iostream>
int main()
{
int i;
for (i=3; i<=5; i++)
std::cout << ( i % 2 == 0 ? "Even" : "Odd" )
<< std::endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// for Loop (P.110) & Increment Operator (P.59)
#include <iostream>
int main()
{
int i;
for (i=3; i<=7; i+=2)
std::cout << ++i << std::endl;
return 0;
}