EGYPTIAN ACADEMY OF ENGINEERING &
Computer Programming ADVANCED TECHNOLOGY
ECO 123 (EAE&AT)
Electrical Engineering Department
Determine the output for each of the following code snippets:
a) b)
for (int i = 0; i < 5; i++)
for (int i = 0; i < 5; i++) {
{ for (int j = 0; j < 5; j++)
for (int j = 0; j < 5; j++) if (i == j || i == 4 - j)
printf("*"); printf("*");
printf("\n"); else
} printf(" ");
printf("\n");
}
c) d)
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++) {
{ for (int j = 0; j < 5; j++)
for (int j = 0; j < 5; j++) if (abs(i - 2) == 2 || abs(j - 2) == 2)
if ((i + j) % 2 == 0) printf("*");
printf("*"); else
else printf(" ");
printf(" "); printf("\n");
printf("\n"); }
}
e) f)
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
for (int j = 0; j <= 5; j++) { for (int j = 0; j <= 5; j++) {
if (j == i + 1) break; if (j == i) continue;
printf("%d",j); printf("%d",j);
} }
printf("\n"); printf("\n");
} }
g)
int i = 0;
do
{
printf("%d \n",++i);
printf("%d \n",i++);
}
while (i < 5);
-1-
EGYPTIAN ACADEMY OF ENGINEERING &
Computer Programming ADVANCED TECHNOLOGY
ECO 123 (EAE&AT)
Electrical Engineering Department
a) b)
0 1 2 3 4 0 1 2 3 4
* * * * *
0 0 * *
* * * * *
1 1 * *
* * * * *
2 2 *
* * * * *
3 3 * *
* * * * *
4 4 * *
c) d)
0 1 2 3 4
0 1 2 3 4
0 * * * * *
0 * * *
1 * *
1 * *
2 * *
2 * * *
3 * *
3 * *
4 * * * * *
4 * * *
e) f)
0 12345
01 02345
012 01345
0123 01245
01234 01235
-2-
EGYPTIAN ACADEMY OF ENGINEERING &
Computer Programming ADVANCED TECHNOLOGY
ECO 123 (EAE&AT)
Electrical Engineering Department
g)
1
1
3
3
5
5
2) Write a full program including three functions for printing the following
patterns using only one '*' and one ' ' per function.
a) b) c)
***** * * *
* * ** ***
* * * * *****
* * ** ***
***** * * *
-3-