0% found this document useful (0 votes)
25 views3 pages

Looping

The document contains code snippets and their corresponding outputs for various programming exercises, primarily focusing on nested loops and conditional statements in C. It includes patterns generated by the code, such as stars and spaces, and specifies the expected output for each snippet. Additionally, it requests a full program with three functions to print specific patterns using a single '*' and a single ' ' per function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Looping

The document contains code snippets and their corresponding outputs for various programming exercises, primarily focusing on nested loops and conditional statements in C. It includes patterns generated by the code, such as stars and spaces, and specifies the expected output for each snippet. Additionally, it requests a full program with three functions to print specific patterns using a single '*' and a single ' ' per function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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-

You might also like