diff --git a/notebook/pt/c51oo/s01primos/s01exercicios/primos01.ipynb b/notebook/pt/c51oo/s01primos/s01exercicios/primos01.ipynb index 4ccf955..2b1975f 100644 --- a/notebook/pt/c51oo/s01primos/s01exercicios/primos01.ipynb +++ b/notebook/pt/c51oo/s01primos/s01exercicios/primos01.ipynb @@ -1,119 +1 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "central-briefing", - "metadata": {}, - "source": [ - "# Números Primos" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "senior-stack", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Este numero eh primo" - ] - } - ], - "source": [ - "#include \n", - "\n", - "int main() {\n", - " int numero = 7,\n", - " flag=0;\n", - "\n", - " for (int i = 2; i < numero; i++)\n", - " if (numero % i == 0)\n", - " flag = 1;\n", - "\n", - " if (flag == 0)\n", - " printf(\"Este numero eh primo\");\n", - " else\n", - " printf(\"Não eh primo\");\n", - "\n", - "\n", - " return 0;\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "incoming-defeat", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n", - "2\n", - "3\n", - "5\n", - "7\n", - "11\n", - "13\n", - "17\n", - "19\n", - "23\n" - ] - } - ], - "source": [ - "#include \n", - "\n", - "int main() {\n", - " int n = 10,\n", - " flag;\n", - "\n", - " int numero = 1;\n", - " int t = 0;\n", - " while (t < n) {\n", - " flag = 0;\n", - " for (int i = 2; i < numero; i++)\n", - " if (numero % i == 0)\n", - " flag = 1;\n", - "\n", - " if (flag == 0) {\n", - " printf(\"%d\\n\", numero);\n", - " t++;\n", - " }\n", - " \n", - " numero++;\n", - " }\n", - "\n", - " return 0;\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "accurate-hometown", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "C", - "language": "c", - "name": "c" - }, - "language_info": { - "file_extension": ".c", - "mimetype": "text/plain", - "name": "c" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} +{"metadata":{"kernelspec":{"display_name":"C","language":"c","name":"c"},"language_info":{"file_extension":".c","mimetype":"text/plain","name":"c"}},"nbformat_minor":5,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Números Primos","metadata":{}},{"cell_type":"code","source":"#include \n\nint main() {\n int numero = 7,\n flag=0;\n\n for (int i = 2; i < numero; i++)\n if (numero % i == 0)\n flag = 1;\n\n if (flag == 0)\n printf(\"Este numero eh primo\");\n else\n printf(\"Não eh primo\");\n\n\n return 0;\n}","metadata":{},"execution_count":3,"outputs":[{"name":"stdout","output_type":"stream","text":"Este numero eh primo"}]},{"cell_type":"code","source":"#include \n\nint main() {\n int n = 10,\n flag;\n\n int numero = 1;\n int t = 0;\n while (t < n) {\n flag = 0;\n for (int i = 2; i < numero; i++)\n if (numero % i == 0)\n flag = 1;\n\n if (flag == 0) {\n printf(\"%d\\n\", numero);\n t++;\n }\n \n numero++;\n }\n\n return 0;\n}","metadata":{},"execution_count":2,"outputs":[{"name":"stdout","output_type":"stream","text":"1\n2\n3\n5\n7\n11\n13\n17\n19\n23\n"}]},{"cell_type":"markdown","source":"# Exercício\n\nConstrua um gerador de números primos seguindo a lógica de um Tipo Abstrato de Dados.","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]} \ No newline at end of file diff --git a/notebook/pt/c51oo/s01primos/s02resolucao/primos01-resolucao.ipynb b/notebook/pt/c51oo/s01primos/s02resolucao/primos01-resolucao.ipynb new file mode 100644 index 0000000..ff5e77e --- /dev/null +++ b/notebook/pt/c51oo/s01primos/s02resolucao/primos01-resolucao.ipynb @@ -0,0 +1 @@ +{"metadata":{"kernelspec":{"display_name":"C","language":"c","name":"c"},"language_info":{"file_extension":".c","mimetype":"text/plain","name":"c"}},"nbformat_minor":5,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Números Primos","metadata":{}},{"cell_type":"code","source":"#include \n\nint main() {\n int numero = 4,\n flag=0;\n\n for (int i = 2; i < numero; i++)\n if (numero % i == 0)\n flag = 1;\n\n if (flag == 0)\n printf(\"Este numero eh primo\");\n else\n printf(\"Não eh primo\");\n\n\n return 0;\n}","metadata":{"trusted":true},"execution_count":2,"outputs":[{"name":"stdout","text":"Não eh primo","output_type":"stream"}]},{"cell_type":"code","source":"#include \n\nint main() {\n int n = 10,\n flag;\n\n int numero = 1;\n int t = 0;\n while (t < n) {\n flag = 0;\n for (int i = 2; i < numero; i++)\n if (numero % i == 0)\n flag = 1;\n\n if (flag == 0) {\n printf(\"%d\\n\", numero);\n t++;\n }\n \n numero++;\n }\n\n return 0;\n}","metadata":{"trusted":true},"execution_count":5,"outputs":[{"name":"stdout","text":"1\n2\n3\n5\n7\n11\n13\n17\n19\n23\n","output_type":"stream"}]},{"cell_type":"markdown","source":"# Exercício\n\nConstrua um gerador de números primos seguindo a lógica de um Tipo Abstrato de Dados.","metadata":{}},{"cell_type":"code","source":"#include \n\ntypedef struct {\n int n;\n int corrente;\n int primoCorrente;\n} SequenciaPrimos;\n\nSequenciaPrimos novaSequencia(int n) {\n SequenciaPrimos umaSequencia;\n umaSequencia.n = n;\n umaSequencia.corrente = 0;\n umaSequencia.primoCorrente = 0;\n return umaSequencia;\n}\n\nint testaPrimo(int numero) {\n int flag = 1;\n for (int i = 2; i < numero; i++)\n if (numero % i == 0)\n flag = 0;\n return flag;\n}\n\nint proximoPrimo(SequenciaPrimos *sequencia) {\n int retorno = 0;\n if (sequencia->corrente < sequencia->n) {\n sequencia->corrente++;\n int flag;\n do {\n sequencia->primoCorrente++;\n flag = testaPrimo(sequencia->primoCorrente);\n } while (flag == 0);\n retorno = sequencia->primoCorrente;\n }\n return retorno;\n}\n\nint main() {\n SequenciaPrimos sequencia = novaSequencia(10);\n\n int primo = proximoPrimo(&sequencia);\n \n while (primo > 0) {\n printf(\"%d\\n\", primo);\n primo = proximoPrimo(&sequencia);\n }\n\n return 0;\n}","metadata":{"trusted":true},"execution_count":4,"outputs":[{"name":"stdout","text":"1\n2\n3\n5\n7\n11\n13\n17\n19\n23\n","output_type":"stream"}]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]} \ No newline at end of file