From 91c7bad66cac0de9a46cf3705e66690a324358ba Mon Sep 17 00:00:00 2001 From: Guz013 Date: Sat, 11 Apr 2026 10:11:37 -0300 Subject: [PATCH] chore: vscode/uni exercises --- .gitignore | 1 + .vscode/tasks.json | 51 +++++++++++++++++++++++++++----------- strings/ex01.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ strings/ex02.c | 33 ++++++++++++++++++++++++ strings/ex03.c | 29 ++++++++++++++++++++++ 5 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 strings/ex01.c create mode 100644 strings/ex02.c create mode 100644 strings/ex03.c diff --git a/.gitignore b/.gitignore index a8e9658..3c060a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .direnv build +*.exe \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5eb7a3d..f291bae 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,15 +1,38 @@ { - "version": "2.0.0", - "tasks": [ - { - "label": "Compile", - "type": "shell", - "command": "clang -std=c23 -glldb -fstandalone-debug ${relativeFile} -o ${fileBasenameNoExtension}" - }, - { - "label": "Clean", - "type": "shell", - "command": "rm ${fileBasenameNoExtension}" - } - ] -} + "version": "2.0.0", + "tasks": [ + { + "label": "Compile", + "type": "shell", + "command": "clang -std=c23 -glldb -fstandalone-debug ${relativeFile} -o ${fileBasenameNoExtension}" + }, + { + "label": "Clean", + "type": "shell", + "command": "rm ${fileBasenameNoExtension}" + }, + { + "type": "cppbuild", + "label": "C/C++: gcc.exe build active file", + "command": "C:\\msys64\\mingw64\\bin\\gcc.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ] +} \ No newline at end of file diff --git a/strings/ex01.c b/strings/ex01.c new file mode 100644 index 0000000..04f501c --- /dev/null +++ b/strings/ex01.c @@ -0,0 +1,62 @@ +#include + +int main(int argc, char const *argv[]) +{ + while (1) + { + int months = 0; + printf("Digite a quantidade de índices de audência que serão digitados:\n"); + if (scanf("%d", &months) != 1) + { + return 1; + } + if (months < 0) + { + printf("Números negativos não são validos!"); + return 1; + } + + double input, last = 0, sum = 0; + int growing = 1; + + for (int i = 1; i <= months; i++) + { + printf("Digite o índice do mês %d:\n", i); + if (scanf("%lf", &input) != 1) + { + return 1; + } + if (input < 0) + { + printf("Números negativos não são validos!"); + return 1; + } + + sum += input; + if (last > input) + { + growing = 0; + } + last = input; + } + + double avarage = sum / months; + + if (growing == 1) + { + printf("AUDIÊNCIA SEMPRE CRESCENTE. Média de audiência: %.1f\n", avarage); + } + else + { + printf("AUDIÊNCIA NEM SEMPRE CRESCENTE. Média de audiência: %.1f\n", avarage); + } + + printf("Continuar? (S/N)\n"); + char c; + scanf(" %c", &c); + if (c != 'S') + { + return 0; + } + } +} diff --git a/strings/ex02.c b/strings/ex02.c new file mode 100644 index 0000000..82fce8f --- /dev/null +++ b/strings/ex02.c @@ -0,0 +1,33 @@ +#include + +int main(int argc, char const *argv[]) +{ + while (1) + { + int input, sum = 0; + + printf("Digite um número (digite -1 para sair):\n"); + if (scanf("%d", &input) != 1) { + return 1; + } + + if (input < 0 ) { + return 0; + } + + for (int i = 1; i < input; i++) + { + if (input % i == 0) { + sum += i; + } + } + + if (sum == input) { + printf("%d é um número perfeito!\n", input); + } else { + printf("%d não é um número perfeito!\n", input); + } + } + + return 0; +} diff --git a/strings/ex03.c b/strings/ex03.c new file mode 100644 index 0000000..16e915c --- /dev/null +++ b/strings/ex03.c @@ -0,0 +1,29 @@ +#include + +int main(int argc, char const *argv[]) +{ + int input; + printf("Digite um número:\n"); + + if (scanf("%d", &input) != 1) { + return 1; + } + if (input < 0) { + printf("Digite um número positivo!"); + return 1; + } + + int k = 1; + for (int i = 0; i < input; i++) + { + for (int j = 0; j < k; j++) + { + printf("* "); + } + printf("\n"); + k++; + } + + + return 0; +}