-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
2 additions
and
119 deletions.
There are no files selected for viewing
120 changes: 1 addition & 119 deletions
120
notebook/pt/c51oo/s01primos/s01exercicios/primos01.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <stdio.h>\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 <stdio.h>\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 <stdio.h>\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 <stdio.h>\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":[]}]} |
1 change: 1 addition & 0 deletions
1
notebook/pt/c51oo/s01primos/s02resolucao/primos01-resolucao.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <stdio.h>\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 <stdio.h>\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 <stdio.h>\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":[]}]} |