Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Programación de computadores

Grupo 21

Santiago Ospina Porras

Challenge 4
Código de fuente

Primer punto:
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. for (int i = 0; i < 20; i++) {
6. for (int j = 0; j < (40); j++) cout << ((j % 2 == 0) ? "#" : " ");
7. cout << "\n ";
8. for (int j = 0; j < (38); j++) cout << ((j % 2 == 0) ? "#" : " ");
9. cout << '\n';
10. }
11.}
Segundo punto (solo diagonal superior):
1. #include <iostream>
2. using namespace std;
3. int main()
4. for (int i = 0; i < 20; i++) {
5. for (int j = 0; j < (40 - 2 * i); j++) cout << ((j % 2 == 0) ? "#" : " ");
6. cout << "\n ";
7. for (int j = 0; j < (38 - 2 * i); j++) cout << ((j % 2 == 0) ? "#" : " ");
8. cout << '\n';
9. }
10.}
Segundo punto (Solo diagonal inferior):

1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. for (int i = 19; i >= 0; i--) {
6. for (int j = 0; j < 40; j++) {
7. if (j < 2 * i+2) cout << " ";
8. else cout << ((j % 2 == 0) ? "#" : " ");
9. }
10. cout << "\n ";
11. for (int j = 0; j < 38; j++) {
12. if (j < (2 * i)) cout << " ";
13. else cout << ((j % 2 == 0) ? "#" : " ");
14. }
15. cout << '\n';
16. }
17.}
Tercer punto:
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. for (int i = 19; i >= 0; i--) {
6. for (int j = 0; j < 40; j++) {
7. // linea que imprime la mitad superior
8. if (j < 2 * i + 2) cout << ((j % 2 == 0) ? "#" : " ");
9. // linea que imprime la mitad inferior
10. else cout << ((j % 2 == 0) ? "#" : " ");
11. }
12. cout << "\n ";
13. for (int j = 0; j < 38; j++) {
14. // linea que imprime la mitad superior
15. if (j < (2 * i)) cout << ((j % 2 == 0) ? "#" : " ");
16. // linea que imprime la mitad inferior
17. else cout << ((j % 2 == 0) ? "#" : " ");
18. }
19. cout << '\n';
20. }
21.}
Punto extra:
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. cout << "radio: 30" << endl;
6. int radius = 15;
7. for (int y = -20; y<= 20; y++) {
8. for (int x = -20; x <= 20; x++) {
9. cout << ((x * x + y * y) < (radius * radius) ? '@' : ' ') << ' ';
10. }
11. cout << '\n';
12. }
13. }

You might also like