├── .github ├── .gitignore ├── config.yml ├── dependabot.yml ├── labeler.yml └── workflows │ ├── action.yml │ ├── greetings.yml │ └── label.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── control ├── calculadora ├── clasificacion.c ├── compara_if.c ├── do-while-switch-case.c ├── dowhile.c ├── dowhile2.c ├── edad.c ├── fibonacci.c ├── fibonacciv2.c ├── for ├── for.c ├── for2.c ├── for3.c ├── for4.c ├── for5.c ├── for5_1.c ├── for6.c ├── for_matriz.c ├── goto.c ├── if ├── if.c ├── if2.c ├── if_anidado.c ├── operacion ├── operacion.c ├── promedio.c ├── switch_example ├── switch_example.c ├── switchcase.c ├── switchcase_calculadora.c ├── while.c └── while2.c ├── exercises ├── a.out ├── area_triangulo.c ├── array.c ├── csvOutput.c ├── dias_seg.c ├── menu.c ├── promedio.c └── struct_anidadoV2.c ├── files ├── .DS_Store ├── a.out ├── gente.txt ├── read │ ├── FCA.txt │ ├── a.out │ ├── fgetc.c │ ├── fgets.c │ ├── fread.c │ ├── fscanf.c │ └── gente.txt └── write │ ├── a.out │ ├── fwrite.c │ ├── gente.doc │ ├── gente.txt │ └── write.c ├── function ├── a.out ├── cexample.c ├── ejemplo_funcion.c ├── ejemplo_funciones.c ├── funciones.h ├── function ├── function.c ├── function_param.c ├── function_recursive ├── function_recursive.c ├── function_recursive_mutuo ├── function_referencia.c ├── function_valor ├── function_valor.c ├── mutual_recursive_function.c ├── variables_globales.c └── variables_locales.c ├── introduction ├── Hello ├── MiHolamundo ├── a.out ├── area ├── area.c ├── area.o ├── area.pp ├── area.s ├── area2 ├── areaV1 ├── entero.c ├── hello ├── hello.c ├── hello.o ├── locale.c ├── locale_ASCII.c └── midir │ └── miarchivo.txt ├── memory ├── a.out ├── calloc.c ├── calloc2.c ├── malloc.c ├── malloc2.c └── realloc.c ├── pointer ├── a.out ├── apuntador.c ├── apuntador_arreglo ├── apuntador_arreglo.c ├── apuntador_arreglo2 ├── apuntador_arreglo2.c ├── apuntador_struct.c ├── for5_1 └── for5_1.c ├── struct ├── a.out ├── data.h ├── data3.h ├── enum.c ├── enum2.c ├── struct ├── struct.c ├── struct2.c ├── struct3.c ├── struct3_1.c ├── struct4.c ├── struct_anidado.c ├── struct_anidadoV2.c ├── struct_union.c ├── structv2.c ├── union.c └── union2.c └── variables ├── 1_variables ├── a.out ├── tipoDatoformatos.c ├── variables ├── variables.c ├── variables2.c ├── variables_constantes └── variables_constantes.c ├── 2_size ├── a.out ├── size_float ├── size_float.c ├── size_int ├── size_int.c ├── size_of └── size_of.c ├── 3_types ├── asignacion_string ├── asignacion_string.c ├── bool ├── bool.c ├── bool2 ├── bool2.c ├── char ├── char.c └── int.c ├── 4_type_def ├── type_def └── type_def.c ├── 5_operators ├── a.out ├── incremento_decremento ├── incremento_decremento.c ├── operadores_logicos ├── operadores_logicos.c ├── operadores_racionales └── operadores_racionales.c ├── 6_read ├── fgets.c ├── get_put_char.c ├── scan.c ├── scanf.c └── scanf2.c ├── 7_operations ├── comparacion.c ├── comparacion_dos ├── comparacion_dos.c ├── conversion └── conversion.c └── 8_conversion ├── conversion.c └── forced_conversion.c /.github/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf -------------------------------------------------------------------------------- /.github/config.yml: -------------------------------------------------------------------------------- 1 | # Configuration for welcome - https://github.com/behaviorbot/welcome 2 | 3 | # Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome 4 | 5 | # Comment to be posted to on first time issues 6 | newIssueWelcomeComment: > 7 | Thanks for opening your first issue here! Be sure to follow the issue template! 8 | 9 | # Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome 10 | 11 | # Comment to be posted to on PRs from first time contributors in your repository 12 | newPRWelcomeComment: > 13 | Thanks for opening this pull request!, You´re great student 14 | 15 | # Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge 16 | 17 | # Comment to be posted to on pull requests merged by a first time user 18 | firstPRMergeComment: > 19 | Congrats on merging your first pull request! We here at behaviorbot are proud of you! 20 | 21 | # It is recommended to include as many gifs and emojis as possible! 22 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "github-actions" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | "Introduction": 2 | - "introduction/*/*" 3 | 4 | "Data types": 5 | - "variables/*/*" 6 | 7 | "Control Structures": 8 | - "control/*/*" 9 | 10 | "Functions": 11 | - "function/*/*" 12 | 13 | "Structures": 14 | - "struct/*/*" 15 | 16 | "Pointers": 17 | - "pointer/*/*" 18 | 19 | "Dynamic Memory": 20 | - "memory/*/*" 21 | 22 | "Files": 23 | - "files/*/*" 24 | 25 | "Exercises": 26 | - "exercises/*/*" 27 | -------------------------------------------------------------------------------- /.github/workflows/action.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | name: Checkout 3 | 4 | # Controls when the workflow will run 5 | on: 6 | # Triggers the workflow on push or pull request events but only for the master branch 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | # Allows you to run this workflow manually from the Actions tab 13 | workflow_dispatch: 14 | 15 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 16 | jobs: 17 | # This workflow contains a single job called "build" 18 | build: 19 | # The type of runner that the job will run on 20 | runs-on: ubuntu-latest 21 | 22 | # Steps represent a sequence of tasks that will be executed as part of the job 23 | steps: 24 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 25 | - uses: actions/checkout@v2.4.0 26 | 27 | # Runs a single command using the runners shell 28 | - name: Run a one-line script 29 | run: echo Check Out! 30 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [pull_request, issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | permissions: 9 | issues: write 10 | pull-requests: write 11 | steps: 12 | - uses: actions/first-interaction@v1 13 | with: 14 | repo-token: ${{ secrets.GITHUB_TOKEN }} 15 | issue-message: 'Congrats for your first issue.' 16 | pr-message: 'First pull request created' 17 | -------------------------------------------------------------------------------- /.github/workflows/label.yml: -------------------------------------------------------------------------------- 1 | # This workflow will triage pull requests and apply a label based on the 2 | # paths that are modified in the pull request. 3 | # 4 | # To use this workflow, you will need to set up a .github/labeler.yml 5 | # file with configuration. For more information, see: 6 | # https://github.com/actions/labeler 7 | 8 | name: Labeler 9 | on: [pull_request] 10 | 11 | jobs: 12 | label: 13 | 14 | runs-on: ubuntu-latest 15 | permissions: 16 | contents: read 17 | pull-requests: write 18 | 19 | steps: 20 | - uses: actions/labeler@v3.0.2 21 | with: 22 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | */*.out 35 | */*/*.out 36 | *.app 37 | *.i*86 38 | *.x86_64 39 | *.hex 40 | 41 | # Debug files 42 | *.dSYM/ 43 | *.su 44 | *.idb 45 | *.pdb 46 | 47 | # Kernel Module Compile Results 48 | *.mod* 49 | *.cmd 50 | .tmp_versions/ 51 | modules.order 52 | Module.symvers 53 | Mkfile.old 54 | dkms.conf 55 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at programacion@danj.rosales.com.mx . All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Daniel de J. Rosales M. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [C Classroom](https://classroom.github.com/classrooms/49954342-taller-programacion-classroom) 2 | [![Checkout](https://github.com/taller-programacion/C/actions/workflows/action.yml/badge.svg)](https://github.com/taller-programacion/C/actions/workflows/action.yml) 3 | [![Labeler](https://github.com/taller-programacion/C/actions/workflows/label.yml/badge.svg?branch=master)](https://github.com/taller-programacion/C/actions/workflows/label.yml) 4 | [![Greetings](https://github.com/taller-programacion/C/actions/workflows/greetings.yml/badge.svg)](https://github.com/taller-programacion/C/actions/workflows/greetings.yml) 5 | [![wakatime](https://wakatime.com/badge/user/bbd1ffab-8ecd-4925-89f8-871387792d21/project/c8217ee0-b696-4768-a581-acf1cb728c15.svg)](https://wakatime.com/badge/user/bbd1ffab-8ecd-4925-89f8-871387792d21/project/c8217ee0-b696-4768-a581-acf1cb728c15) 6 | 7 | ### [1. Introduction](https://github.com/taller-programacion/C/tree/master/introduction) 8 | ### [2. C data types](https://github.com/taller-programacion/C/tree/master/variables) 9 | ### [3. Control structures](https://github.com/taller-programacion/C/tree/master/control) 10 | ### [4. C functions](https://github.com/taller-programacion/C/tree/master/function) 11 | ### [5. The C struct and header files](https://github.com/taller-programacion/C/tree/master/struct) 12 | ### [6. Pointers ](https://github.com/taller-programacion/C/tree/master/pointer) 13 | ### [7. Dynamic memory allocation](https://github.com/taller-programacion/C/tree/master/memory) 14 | ### [8. Files](https://github.com/taller-programacion/C/tree/master/files) 15 | ### [9. Exercises](https://github.com/taller-programacion/C/tree/master/exercises) 16 | 17 | # [MIT License](https://github.com/taller-programacion/C/blob/master/LICENSE) 18 | 19 | Copyright (c) 2021 [Daniel de J. Rosales M.](https://dannascornell.github.io/) 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy 22 | of this software and associated documentation files (the "Software"), to deal 23 | in the Software without restriction, including without limitation the rights 24 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 25 | copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all 29 | copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 37 | SOFTWARE. 38 | -------------------------------------------------------------------------------- /control/calculadora: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/control/calculadora -------------------------------------------------------------------------------- /control/clasificacion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /*Clasificación de videojuegos*/ 4 | /* 5 | Clasificación "A". Contenido para todo público. ... 6 | Clasificación "B". Contenido para adolescentes a partir de 12 años. ... 7 | Clasificación "B15". Contenido para mayores de 15 años. ... 8 | Clasificación "C". Contenido no apto para personas menores de 18 años. ... 9 | Clasificación "D". > 21 10 | */ 11 | int main(){ 12 | 13 | int anio, edad, opc; //Declaración de variables 14 | 15 | printf("Introduce tu anio de nacimiento:"); 16 | scanf("%d", &anio); 17 | 18 | //Cálculo de edad 19 | edad = 2021 - anio; 20 | printf("\nTienes %d anios\n", edad); 21 | 22 | if(edad >= 12 && edad < 15){ 23 | printf("Puedes seleccionar de nuestro catálogo A y B"); 24 | printf("\nElige una opción:\n 1.- toda la familia\n 2.- Adolescentes\n"); 25 | scanf("%d", &opc); 26 | switch(opc){ 27 | case 1: 28 | printf("\nt1.- Free fire \n 2.- Minecraft"); 29 | break; 30 | case 2: 31 | printf("\nt1.- Fornite \n 2.- Pokemon"); 32 | break; 33 | default: 34 | printf("\nElige una opción válida"); 35 | break; 36 | } 37 | } 38 | else if(edad >= 15 && edad < 18 ){ // 15 - 17 39 | printf("Puedes seleccionar de nuestro catálogo A, B y B-15"); 40 | printf("\nElige una opción:\n 1.- toda la familia\n 2.- Adolescentes\n 3.- Mayores de 15\n"); 41 | scanf("%d", &opc); 42 | switch(opc){ 43 | case 1: 44 | printf("\nt1.- Free fire \n 2.- Minecraft"); 45 | break; 46 | case 2: 47 | printf("\n\t1.- Fornite \n 2.- Pokemon"); 48 | break; 49 | case 3: 50 | printf("\n\t1.- Call of Duty \n 2.- Gears of War"); 51 | default: 52 | printf("\nElige una opción válida"); 53 | break; 54 | } 55 | } 56 | else if(edad >= 18 && edad < 21){ // 18 - 20 57 | printf("Puedes seleccionar de nuestro catálogo A, B, B-15 y C"); 58 | printf("\nElige una opción:\n 1.- toda la familia\n 2.- Adolescentes\n 3.- Mayores de 15\n 4.- Adultos\n"); 59 | scanf("%d", &opc); 60 | switch(opc){ 61 | case 1: 62 | printf("\n\t1.- Free fire \n 2.- Minecraft"); 63 | break; 64 | case 2: 65 | printf("\n\t1.- Fornite \n 2.- Pokemon"); 66 | break; 67 | case 3: 68 | printf("\n\t1.- Call of Duty \n 2.- Gears of War"); 69 | case 4: 70 | printf("\n\t1.- Mortal Kombat \n 2.- Grand Theft Auto"); 71 | default: 72 | printf("\nElige una opción válida"); 73 | break; 74 | } 75 | } 76 | else if(edad >=21){ // 21 - n-1 77 | printf("Puedes seleccionar de nuestro catálogo A, B, B-15, C y D"); 78 | printf("\nElige una opción :\n 1.- toda la familia\n 2.- Adolescentes\n 3.- Mayores de 15\n 4.- Adultos\n 5.- Mayores de 21\n"); 79 | scanf("%d", &opc); 80 | switch(opc){ 81 | case 1: 82 | printf("\n\t1.- Free fire \n 2.- Minecraft"); 83 | break; 84 | case 2: 85 | printf("\n\t1.- Fornite \n 2.- Pokemon"); 86 | break; 87 | case 3: 88 | printf("\n\t1.- Call of Duty \n 2.- Gears of War"); 89 | case 4: 90 | printf("\n\t1.- Mortal Kombat \n 2.- Grand Theft Auto"); 91 | case 5: 92 | printf("\n\t1.- Manhunt \n2.- Doom"); 93 | default: 94 | printf("\nElige una opción válida"); 95 | break; 96 | } 97 | } 98 | else{ 99 | printf("Puedes seleccionar de nuestro catálogo Clasificación A"); 100 | printf("\nt1.- Free fire \n 2.- Minecraft"); 101 | } 102 | return 0; 103 | } -------------------------------------------------------------------------------- /control/compara_if.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | Encontrar el mayor de dos números 4 | */ 5 | 6 | //Declarando e inicializando variables 7 | int x=0; 8 | int y=0; 9 | int z=0; 10 | 11 | int main(void){ 12 | //Pedir valores a usuario 13 | printf("\tIngresa un número: "); 14 | scanf("%d",&x); 15 | printf("\tIngresa un número: "); 16 | scanf("%d",&y); 17 | printf("\tIngresa un número: "); 18 | scanf("%d",&z); 19 | 20 | //Estructura de control de selección simple 21 | if(x==y && y==z){//Igualdades 22 | printf("%d es igual a %d y %d", x, y, z); 23 | }else{ // Comparaciones 24 | if(x>y){ 25 | if(y>z){ 26 | printf("%d es mayor que %d y %d", x, y, z); 27 | }else{ 28 | printf("%d es mayor que %d y %d", z, x, y); 29 | } 30 | }else{ 31 | if(y>z){ 32 | printf("%d es mayor que %d y %d", y, x, z); 33 | }else{ 34 | printf("%d es mayor que %d y %d", z, x, y); 35 | } 36 | } 37 | } 38 | /* 39 | if(x==y){ 40 | printf("\nEsto es un IF\n"); 41 | printf("%d es igual que %d", x, y); 42 | }else if(x>y){ 43 | printf("\nEsto es un ELSIF\n"); 44 | printf("%d es mayor que %d", x, y); 45 | }else{ 46 | printf("\nEsto es un ELSE\n"); 47 | printf("%d es mayor que %d", y, x); 48 | } 49 | */ 50 | printf("\nFin de programa\n"); 51 | return 0; 52 | 53 | } -------------------------------------------------------------------------------- /control/do-while-switch-case.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | //Declarando variables 7 | int opcion; 8 | float n1, n2, resultado; 9 | 10 | do{ 11 | system("pause"); 12 | system("cls"); //Limpiar pantalla 13 | printf("Elige una opcion:\n"); 14 | printf("\t 1.- Suma\n"); 15 | printf("\t 2.- Resta\n"); 16 | printf("\t 3.- Division\n"); 17 | printf("\t 4.- Multiplicacion\n"); 18 | printf("\t 5.- Potencia\n"); 19 | printf("\t 6.- Raiz cuadrada\n"); 20 | printf("\t 7.- Salir\n"); 21 | scanf("%d",&opcion); 22 | system("cls"); //Limpiar pantalla 23 | 24 | if(opcion==6){ 25 | printf("\nDame el primer valor: "); 26 | scanf("%f", &n1); 27 | } 28 | else if(opcion>=7){ 29 | 30 | } 31 | else{ 32 | printf("\nDame el primer valor: "); 33 | scanf("%f", &n1); 34 | printf("\nDame el segundo valor: "); 35 | scanf("%f", &n2); 36 | } 37 | 38 | //Estructura de control de selección multiple 39 | 40 | switch(opcion) 41 | { 42 | case 1: 43 | resultado = n1 + n2; 44 | printf("%f", resultado); 45 | break; 46 | case 2: 47 | resultado = n1 - n2; 48 | printf("%f", resultado); 49 | break; 50 | case 3: 51 | if(n2==0) 52 | { 53 | printf("La operacion entre 0 no esta definida"); 54 | } 55 | else{ 56 | resultado = n1 / n2; 57 | printf("%f", resultado); 58 | } 59 | break; 60 | case 4: 61 | resultado = n1 * n2; 62 | printf("%f", resultado); 63 | break; 64 | case 5: 65 | resultado = pow(n1,n2); 66 | printf("%f", resultado); 67 | break; 68 | case 6: 69 | if(n1<0){ 70 | printf("No esta definida"); 71 | } 72 | else{ 73 | resultado = sqrt(n1); 74 | printf("%f", resultado); 75 | } 76 | break; 77 | default: 78 | printf("Salir"); 79 | exit(0); 80 | } //Sale break 81 | }while(opcion<7); 82 | } 83 | -------------------------------------------------------------------------------- /control/dowhile.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | 6 | int n, a; 7 | a = 0; 8 | 9 | do 10 | { 11 | printf( "Introduzca un numero entero: " ); 12 | scanf( "%d", &n ); 13 | 14 | if ( n == 0 ) 15 | { 16 | printf( "ERROR: El cero no tiene negativo.\n" ); 17 | //continue; 18 | //break; 19 | } 20 | printf( "El negativo es: %d\n", -n ); 21 | //a += n; 22 | a = a + n; 23 | } while ( n >= -10 && n <= 10 ); 24 | 25 | printf( "Suma: %d", a ); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /control/dowhile2.c: -------------------------------------------------------------------------------- 1 | #include //Librerías 2 | 3 | int main(){ 4 | 5 | int a = 0; //Declaración de variables 6 | do{ //Inicia Do-while 7 | printf("Iteración número %d\n", a); //a = 1 8 | a++; //a = 2 9 | }while(a < 1); //2 < 1 -> False 10 | printf("Fin de Programa, valor actual de a es %d\n", a); // 2 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /control/edad.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | Descripción: Dependiendo de la edad se mostrará cierta información 5 | */ 6 | 7 | int edad; 8 | 9 | void main(){ 10 | 11 | printf("\nDame tu edad:"); 12 | scanf("%i", &edad); //17 13 | if(edad >0 && edad < 14){ // 12 >=14 -> false AND 12 < 18 -> true = false 14 | //BLOQUE1 15 | printf("\nTienes %i anios, eres generación z:", edad); 16 | }else if(edad >= 14 && edad < 18){ // 512 < 14 ? -> true 17 | //BLOQUE2 18 | printf("\nTienes %i anios, eres generación alpha:", edad); 19 | }else if(edad >=18 && edad < 50){ // 54 > 50 ? -> true 20 | //BLOQUE3 21 | printf("\nTienes %i anios, eres Baby Bommer:", edad); 22 | }else if(edad >=50 && edad <=120){ // 54 > 50 ? -> true 23 | //BLOQUE4 24 | printf("\nTienes %i anios, eres generación x:", edad); 25 | } 26 | else{ 27 | //BLOQUE5 28 | printf("No es una edad válida"); 29 | } 30 | printf("\nFIN DE PROGRAMA:"); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /control/fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(void) 4 | { 5 | int x,y,z,cont,paro; 6 | x=0; 7 | y=1; 8 | printf("Cuantos numeros quieres? "); 9 | scanf("%d", &paro); 10 | 11 | if(paro==1){ 12 | printf("%d\n",x); 13 | } 14 | else if(paro==2){ 15 | printf("%d\n%d\n",x, y); 16 | /* printf("%d\n",x); 17 | printf("%d\n",y);*/ 18 | } 19 | else{ 20 | printf("%d\n%d\n",x, y); 21 | for (cont=0;cont 2 | #include 3 | 4 | int main(void) 5 | { 6 | int x,y,z,cont,stop; 7 | 8 | x=0; 9 | y=1; 10 | z=0; 11 | 12 | printf("Cuantos números deseas: "); 13 | scanf("%d", &stop); 14 | 15 | //printf("0\n1\n"); 16 | //for(inicio; paro; incremento/decremento){} 17 | 18 | for (cont=0;cont 2 | #include 3 | 4 | int main(void){ 5 | int cont=1; 6 | /* 7 | for(inicio; fin; incremento/decremento){ 8 | //TODO 9 | } 10 | */ 11 | 12 | for (cont=0;cont<=100;cont++){ //cont = 4; 4<=3 13 | //x=cont+y; 14 | printf("\tValor: %d\n",cont); //Valor: 3\n 15 | if(cont==50){ 16 | break; 17 | } 18 | //y++; 19 | /*x=y; 20 | y=z;*/ 21 | } 22 | printf("Valor final: %d\n",cont); //Valor final : 4\n 23 | getchar(); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /control/for2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | //#include 4 | //#include 5 | 6 | int main(void){ 7 | 8 | int x,y,z,cont; 9 | 10 | for (x=0;x<=5;x++){ 11 | for (y=0;y<=5;y++){ 12 | if(x>=y){ 13 | printf("[@,@]"); 14 | }else{ 15 | printf("[%d,%d]",x,y); 16 | } 17 | } 18 | printf("\n"); 19 | } 20 | getchar(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /control/for3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | //#include 4 | //#include 5 | 6 | int main(void) 7 | { 8 | int x,y,z,cont; 9 | for (x=0;x<=5;x++){ 10 | for (y=0;y<=5;y++){ 11 | printf("[%d]\t",x+y); 12 | } 13 | printf("\n"); 14 | } 15 | getchar(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /control/for4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | //#include 4 | //#include 5 | 6 | int main(void) 7 | { 8 | int x,y,z,cont; 9 | z=1; 10 | for (x=0;x<=5;x++){ 11 | for (y=0;y<=5;y++){ 12 | printf("[%d]",z); 13 | z++; 14 | } 15 | printf("\n"); 16 | } 17 | getchar(); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /control/for5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | int x,y,z,cont,stop; 7 | 8 | x=0; 9 | y=1; 10 | z=0; 11 | 12 | printf("Cuantos números deseas: "); 13 | scanf("%d", &stop); 14 | 15 | //printf("0\n1\n"); 16 | //for(inicio; paro; incremento/decremento){} 17 | if(stop<=2){ 18 | for (cont=0;cont 2 | #include 3 | int main(void) 4 | { 5 | int x,y,z,cont; 6 | x=0; 7 | y=1; 8 | for (cont=0;cont<20;cont++) 9 | { 10 | z=x+y; 11 | printf("%d\n",z); 12 | x=y; 13 | y=z; 14 | } 15 | getchar(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /control/for6.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | //0 1 2....9 10 5 | for(int x=0; x < 5; x++){ 6 | for(int y=0; y < 5; y++){ 7 | if(x>=y){ 8 | printf("\t[0, 0]"); 9 | }else{ 10 | printf("\t[%d, %d]", x, y); 11 | } 12 | } 13 | printf("\n"); 14 | } 15 | return 0; 16 | } -------------------------------------------------------------------------------- /control/for_matriz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | int fil, col, num; 7 | num=0; 8 | for (fil=1;fil<=10;fil++){ 9 | for (col=1;col<=5;col++){ 10 | printf("%d\t",num); 11 | num++; 12 | } 13 | printf("\n"); 14 | } 15 | getchar(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /control/goto.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | 6 | int n, a; 7 | 8 | a = 0; 9 | do 10 | { 11 | printf( "Introduzca un numero entero: " ); 12 | scanf( "%d", &n ); 13 | 14 | if ( n == 0 ) 15 | { 16 | printf( "ERROR: El cero no tiene opuesto.\n" ); 17 | goto imprimeresultado; 18 | } 19 | printf( "El opuesto es: %d\n", -n ); 20 | a += n; 21 | } while ( n >= -10 && n <= 10 ); 22 | 23 | 24 | imprimeresultado: 25 | printf( "Suma: %d", a ); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /control/if: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/control/if -------------------------------------------------------------------------------- /control/if.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | float cm, pul, valor; 5 | char unidad; 6 | printf("Introduce número y unidad (p=pulg. o c=cm: "); 7 | scanf("%f %c",&valor, &unidad); 8 | 9 | if (unidad=='p') 10 | { 11 | cm=valor*2.54; 12 | printf("Las %f pulgadas son %f centímetros\n",valor,cm); 13 | } 14 | if (unidad=='c') 15 | { 16 | pul=valor/2.54; 17 | printf("Los %f centímetros son %f pulgadas\n",valor,pul); 18 | } 19 | if (unidad!='c' || unidad!='p') 20 | { 21 | printf("Valores incorrectos"); 22 | } 23 | 24 | else 25 | { 26 | printf("Fin de programa\n"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /control/if2.c: -------------------------------------------------------------------------------- 1 | #include 2 | //Comparar edades 3 | int main(){ 4 | 5 | int edad=0; 6 | 7 | printf("Introduce tu edad [0-150]: "); 8 | scanf("%d",&edad); // 30 9 | 10 | //operadores lógicos 11 | // AND -> && 12 | // OR -> || 13 | // NOT -> ! 14 | if (edad > 0 && edad <= 12){ // 1 - 12 15 | printf("Eres generación alpha y tienes %d",edad); 16 | if(edad < 9){ 17 | printf("\nEres un infante"); 18 | }else{ 19 | printf("\nEres aborrecente"); 20 | } 21 | }else if (edad > 12 && edad <= 25){ // else if (30 < 25) -> false 22 | printf("Eres generación y, y tienes %d anios",edad); 23 | // 35....32605 24 | }else if (edad > 25 && edad <= 45){ // else if (30 < 25) -> false 25 | printf("Eres generación x, y tienes %d anios",edad); 26 | // 35....32605 27 | }else if (edad > 45 && edad < 150){ // else if (30 < 25) -> false 28 | printf("Eres generación BB, y tienes %d anios",edad); 29 | // 35....32605 30 | } 31 | else{ 32 | printf("Introduce una edad válida [0-150]"); 33 | } 34 | printf("\nFin programa"); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /control/if_anidado.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float n1, n2, n3; 6 | 7 | printf( "%s","Introduzca el primer número: "); 8 | scanf( "%f", &n1 ); 9 | printf( "%s","Introduzca el segundo número: "); 10 | scanf( "%f", &n2 ); 11 | printf( "%s","Introduzca el primer número: "); 12 | scanf( "%f", &n3 ); 13 | 14 | if ( n1 >= n2 && n1 >= n3 ){ 15 | printf( "\n %f es el mayor.", n1 ); 16 | }else{ 17 | 18 | if ( n2 > n3 ){ 19 | printf( "\n %f es el mayor.", n2 ); 20 | }else{ 21 | printf( "\n %f es el mayor.", n3 ); 22 | } 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /control/operacion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/control/operacion -------------------------------------------------------------------------------- /control/operacion.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | Autor: DanJ 4 | Descripción: División entre dos números enteros 5 | IF ELSE ELSE IF 6 | Estructura de Selección Simple 7 | */ 8 | 9 | /*Declaramos variables*/ 10 | int num1 = 0; 11 | int num2 = 0; 12 | int resultado = 0; 13 | 14 | int main(){ 15 | //Operación 16 | printf("\n\tDivisión entre dos números"); 17 | printf("\n-------------------------------\n"); 18 | printf("Dame el primer número:"); 19 | scanf("%i", &num1); //100 20 | printf("Dame el segundo número:"); 21 | scanf("%i", &num2); //5 22 | if(num2 == 0){ // ¿ 5 == 0 ? => false 23 | printf("La división entre 0 no está definida"); 24 | printf("\n\tFIN DEL IF\n"); 25 | }else{ 26 | resultado = num1 / num2; 27 | printf("\n\tEl resultado de dividir %i entre %i es %i\n", num1, num2, resultado); 28 | printf("\n\tFIN DEL ELSE\n"); 29 | } 30 | printf("\n\tFIN DEL PROGRAMA\n"); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /control/promedio.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | Descripcion: Calcular promedio de un alumno o alumna 4 | */ 5 | 6 | char nomMateria; //Variable Global 7 | double promedio = 0; 8 | 9 | int main(){ 10 | int cont; 11 | double calificaciones[]={10, 9, 9.5, 11, 9.6, 9, 10}; 12 | //Declarando arreglo de flotantes 13 | 14 | for(cont = 0; cont < 7; cont++){ 15 | printf("Calificacion: %0.2lf\n", calificaciones[cont]); 16 | 17 | promedio += calificaciones [cont]; 18 | } 19 | printf("Contador final %d\n", cont); 20 | printf("\tPromedio: %0.2f\n", promedio/cont); 21 | 22 | printf("Fin de programa"); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /control/switch_example: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/control/switch_example -------------------------------------------------------------------------------- /control/switch_example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | /* 5 | Switch-Case: Estructura de selección múltiple 6 | Descripción: Menú telefónico 7 | */ 8 | 9 | int main(){ 10 | 11 | int opcion; //Declarando variable opcion 12 | char opcion2; //Declarando variable opcion 13 | // char opcion3[10] ='Hola'; 14 | // char variable = 'A'; 15 | 16 | printf("Bienvenido a nuestro centro telefónico..bla bla bla..."); 17 | printf("\nElige una opción [1-4]:\n"); 18 | printf("\t1.- Quejas o sugerencias\n"); 19 | printf("\t2.- Pagos\n"); 20 | printf("\t3.- Revisar términos y condiciones\n"); 21 | printf("\t4.- Salir\n"); 22 | scanf("%d", &opcion); //Pidiendo al usuario un dígito 23 | 24 | while(opcion != 4){ 25 | printf ("Opcion vale: %d", opcion); //Bandera 26 | switch(opcion){ //switch(1){...} 27 | case 1: 28 | printf("\n\tUno de nuestros agentes atenderá su caso, espere en la línea..."); 29 | break; 30 | case 2: 31 | //Submenú 32 | printf("\n\t\tElige una opción [A-D]:\n"); 33 | printf("\t\tA.- Consulta de Saldo\n"); 34 | printf("\t\tB.- Pagar servicio\n"); 35 | printf("\t\tC.- Hablar con un ejecutivo\n"); 36 | printf("\t\tD.- Salir\n"); 37 | 38 | scanf("%s", &opcion2); //Pidiendo al usuario un dígito 39 | //fflush(stdin); 40 | //opcion2 = getchar(); 41 | switch(opcion2){ 42 | case 'A': 43 | printf("\t\t\tSaldo actual es de $250.00"); 44 | break; 45 | case 'B': 46 | printf("\t\t\tPagando...."); 47 | printf("\n\t\t\tAdeudo actual es de $0.0"); 48 | break; 49 | case 'C': 50 | printf("\t\t\tEspere en la línea"); 51 | break; 52 | case 'D': 53 | printf("\n\t\t\tAgradecemos su llamada...pero estamos de vacaciones, ¡NO MOLESTE!"); 54 | break; 55 | default: 56 | printf("\n\tElige una opción válida..."); 57 | break; 58 | } 59 | break; 60 | case 3: 61 | printf("\n\tBla bla bla bla bla bla..."); 62 | //TODO 63 | break; 64 | //... 65 | //... 66 | case 4: 67 | printf("\n\tAgradecemos su llamada...pero estamos de vacaciones, ¡NO MOLESTE!"); 68 | break; 69 | default: 70 | printf("\n\tElige una opción válida..."); 71 | break; 72 | } //Fin Switch 73 | } //Fin While 74 | printf("\nFuera del switch"); 75 | return 0; 76 | } -------------------------------------------------------------------------------- /control/switchcase.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main(){ 7 | //Declarar e inicializar 2 variables (a, b) 8 | float a = 0, b = 0, resultadoSuma = 0; 9 | int operacion, opcion; 10 | 11 | printf("------------------------------"); 12 | printf("\n¿Qué deseas hacer?\n"); 13 | printf("\t1.- Realizar Operaciones\n\t2.- Salir\n"); 14 | printf("------------------------------\n"); 15 | 16 | scanf("%d", &opcion); 17 | 18 | do{ 19 | if (opcion != 1){ 20 | printf("Salir\n"); 21 | exit(0); 22 | }else{ 23 | //Elegir Operación (+, -, *, /) 24 | printf("¿Qué operación deseas?\n "); 25 | printf("1.- Suma \n 2.- Resta \n 3.- Multiplicación \n 4.- División\n 5.- Raíz Cuadrada\n 6.- Potencia\n 7.- Salir\n"); 26 | scanf("%d", &operacion); 27 | 28 | if (operacion == 5){ 29 | printf("Dame el número: "); 30 | scanf("%f", &a); 31 | }else if(operacion == 7){ 32 | printf("Apagando Calculadora...\n"); 33 | }else{ 34 | //Ingresar los datos (a, b) 35 | printf("Dame el primer número: "); 36 | scanf("%f", &a); 37 | printf("Dame el segundo número: "); 38 | scanf("%f", &b); 39 | } 40 | //Imprimir el resultado 41 | switch ( operacion ){ 42 | case 1: 43 | resultadoSuma = a + b; 44 | printf("\tEl resultado de %0.2f + %0.2f = %0.2f\n", a, b, resultadoSuma); 45 | break; 46 | case 2: 47 | printf("\tEl resultado de %0.2f - %0.2f = %0.2f\n", a, b, a - b); 48 | break; 49 | case 3: 50 | printf("\tEl resultado de %0.2f * %0.2f = %0.2f\n", a, b, a * b); 51 | break; 52 | case 4: 53 | //Validar división entre 0 54 | if( b == 0){ 55 | printf("\tLa división entre %f no está definida\n", b); 56 | }else{ 57 | printf("\tEl resultado de %0.2f / %0.2f = %0.2f\n", a, b, a / b); 58 | } 59 | break; 60 | case 5: 61 | if( a < 0){ 62 | printf("\tLa raíz cuadrada de un número negativo no está definida\n", a); 63 | }else{ 64 | printf("\tEl raíz cuadrada de %0.2f es %0.2f\n", a, sqrt(a)); 65 | } 66 | break; 67 | case 6: 68 | printf("\tEl resultado de %0.2f elevado a la %0.2f es %0.2f \n", a, b, pow(a, b)); 69 | break; 70 | case 7: 71 | exit(0); 72 | default: 73 | printf("Elige una opción válida\n"); 74 | } 75 | // printf("Printf fuera del switch\n"); 76 | } 77 | //printf("Printf fuera de else\n"); 78 | }while(operacion != 7); 79 | 80 | return 0; 81 | } -------------------------------------------------------------------------------- /control/switchcase_calculadora.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | //Declarando variables 8 | int opcion; 9 | float n1, n2, resultado; 10 | 11 | printf("Elige una opcion:\n"); 12 | printf("\t 1.- Suma\n"); 13 | printf("\t 2.- Resta\n"); 14 | printf("\t 3.- Division\n"); 15 | printf("\t 4.- Multiplicacion\n"); 16 | printf("\t 5.- Potencia\n"); 17 | printf("\t 6.- Raiz cuadrada\n"); 18 | printf("\t 7.- Salir\n"); 19 | scanf("%d",&opcion); 20 | system("cls"); 21 | 22 | if(opcion==6){ 23 | printf("\nDame el primer valor: "); 24 | scanf("%f", &n1); 25 | } 26 | else if(opcion>=7){ 27 | } 28 | else{ 29 | printf("\nDame el primer valor: "); 30 | scanf("%f", &n1); 31 | printf("\nDame el segundo valor: "); 32 | scanf("%f", &n2); 33 | } 34 | 35 | //Estructura de control de selección multiple 36 | switch(opcion) 37 | { 38 | case 1: 39 | resultado = n1 + n2; 40 | printf("%f", resultado); 41 | break; 42 | case 2: 43 | resultado = n1 - n2; 44 | printf("%f", resultado); 45 | break; 46 | case 3: 47 | if(n2==0) 48 | { 49 | printf("La operacion entre 0 no esta definida"); 50 | } 51 | else{ 52 | resultado = n1 / n2; 53 | printf("%f", resultado); 54 | } 55 | break; 56 | case 4: 57 | resultado = n1 * n2; 58 | printf("%f", resultado); 59 | break; 60 | case 5: 61 | resultado = pow(n1,n2); 62 | printf("%f", resultado); 63 | break; 64 | case 6: 65 | if(n1<0){ 66 | printf("No esta definida"); 67 | } 68 | else{ 69 | resultado = sqrt(n1); 70 | printf("%f", resultado); 71 | } 72 | break; 73 | default: 74 | printf("Salir"); 75 | exit(0); 76 | } //Sale break 77 | } 78 | -------------------------------------------------------------------------------- /control/while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | 6 | int n, a; 7 | a = 0; 8 | 9 | printf( "Introduzca un numero entero: " ); 10 | scanf( "%d", &n ); 11 | 12 | while( n >= -10 && n <= 10 ){ 13 | if ( n == 0 ) 14 | { 15 | printf( "ERROR: El cero no tiene negativo.\n" ); 16 | //continue; 17 | //break; 18 | } 19 | printf( "El opuesto es: %d\n", -n ); 20 | //a += n; 21 | a = a + n; 22 | continue; 23 | } 24 | 25 | printf( "Suma: %d", a ); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /control/while2.c: -------------------------------------------------------------------------------- 1 | #include //Librerías 2 | 3 | int main(){ //Función principal main 4 | 5 | int a = 1; //Declaración de variables 6 | // while(condicion){ //TODO } 7 | while(a < 1){ // 1 < 1 -> False 8 | printf("Iteración número %d\n", a); 9 | a++; 10 | } 11 | printf("Fin de Programa, valor actual de a es %d\n", a); // 1 12 | return 0; 13 | } -------------------------------------------------------------------------------- /exercises/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/exercises/a.out -------------------------------------------------------------------------------- /exercises/area_triangulo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /* 4 | * Área de un tríangulo dados 3 lados 5 | */ 6 | 7 | int main(){ 8 | float l1, l2, l3, sp; //Declaración de variables 9 | double area; 10 | puts("Área de un triangulo."); 11 | printf("Ingresa la longitud del primer lado: "); 12 | scanf("%f", &l1); 13 | printf("Ingresa la longitud del segundo lado: "); 14 | scanf("%f", &l2); 15 | printf("Ingresa la longitud del tercer lado: "); 16 | scanf("%f", &l3); 17 | 18 | sp = (l1 + l2 + l3) / 2;//Obtener Semi perímetro 19 | area = sqrt(sp * (sp - l1) * (sp - l2) * (sp - l3));//formula de Heron 20 | printf("\tEl semi perímetro del triángulo es: %.6f\n", sp); 21 | printf("\tEl area del triángulo es: %.6f\n", area); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /exercises/array.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | Descripcion: Calcular promedio de un alumno o alumna 4 | */ 5 | 6 | char nomMateria; //Variable Global 7 | double promedio = 0; 8 | 9 | int main(){ 10 | int cont, opt; 11 | double calificaciones[10] ={ 9, 5, 5, 10}; 12 | char nombres[20][20]; 13 | printf("\nCuantas calificaciones deseas ingresar: "); 14 | scanf("%i", &opt); 15 | 16 | //Guardar Calificaciones 17 | for(cont = 0; cont < opt; cont++){ // 18 | printf("\n-----------------------------"); 19 | printf("\nDame la asignatura : "); 20 | scanf("%s", nombres[cont]); //nombres = ['I', 'n', 'g', 'l', 'e', 's', '\0', '\0'] 21 | 22 | printf("\nDame la calificacion : "); 23 | scanf("%lf", &calificaciones[cont]); //calificaciones[0] = 10, calificaciones[1] = 9 24 | 25 | printf("Calificacion: %0.2lf\n", calificaciones[cont]); //calificaciones[0] = 10 calificaciones[1] = 9 26 | promedio += calificaciones[cont]; 27 | } 28 | printf("\tPromedio: %0.2f\n", promedio/opt); 29 | 30 | //Consultar Calificaciones 31 | printf("\nDame una posición: "); 32 | scanf("%i", &opt); // 1 33 | 34 | printf("Asignatura: %s\n", nombres[opt-1]); //calificaciones[0] = 10 calificaciones[1] = 9 35 | printf("Calificación: %0.2lf\n", calificaciones[opt-1]); //calificaciones[0] = 10 calificaciones[1] = 9 36 | 37 | printf("Fin de programa"); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /exercises/csvOutput.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | //Struct para almacenar lo ingresado por el usuario 6 | struct datos{ 7 | char nombre[60]; 8 | int edad; 9 | char ciudad[20]; 10 | int telefono; 11 | }persona[10]; 12 | 13 | //Declaración de archivo 14 | FILE *archivo; 15 | 16 | //Función para remover el salto de línea final 17 | void remueveSaltoLinea (char *cadena){ 18 | char *saltoLinea; 19 | saltoLinea = strchr (cadena, '\n'); //Buscar un caracter en una cadena 20 | if (saltoLinea) 21 | *saltoLinea = '\0'; 22 | } 23 | 24 | //Variables 25 | int numReg = 0; 26 | 27 | //Función de captura de datos y escritura en archivo .csv 28 | void capturaDatos(){ 29 | for (int i=0; i 2 | 3 | int main(){ 4 | //Declaración de variables 5 | int dias; 6 | float resultado; 7 | 8 | //Intrucciones para el usuario 9 | printf("Ingresa un número de días para calcular los segundos que tiene: "); 10 | //Leemos la variable dias 11 | scanf("%d", &dias); 12 | resultado = dias * (24 * 60 * 60); 13 | printf("\tEn %d días hay %0.2f segundos.\n", dias, resultado); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /exercises/menu.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | /* 5 | Switch-Case: Estructura de selección múltiple 6 | Descripción: Menú telefónico 7 | */ 8 | 9 | int main(){ 10 | 11 | <<<<<<< HEAD 12 | int opcion; //Declarando variable opcion 13 | ======= 14 | int opcion = 0; //Declarando variable opcion 15 | >>>>>>> 1b80eaa5d12a3ba1683bd1d32aa3c902b054fed6 16 | char opcion2; //Declarando variable opcion 17 | // char opcion3[10] ='Hola'; 18 | // char variable = 'A'; 19 | 20 | <<<<<<< HEAD 21 | printf("------Opcion vale: %i", opcion); 22 | 23 | //for(opcion=0; opcion != 4;){ 24 | do{ // 0 != 4 25 | printf("\n------------------------------------------------------"); 26 | printf("\nBienvenido a nuestro centro telefónico..bla bla bla..."); 27 | printf("\nElige una opción [1-4]:\n"); 28 | printf("\t1.- Quejas o sugerencias\n"); 29 | printf("\t2.- Pagos\n"); 30 | printf("\t3.- Revisar términos y condiciones\n"); 31 | printf("\t4.- Salir\n"); 32 | scanf("%d", &opcion); //Pidiendo al usuario un dígito 33 | 34 | switch(opcion){ //switch(1){...} 35 | case 1: 36 | printf("\n\tUno de nuestros agentes atenderá su caso, espere en la línea..."); 37 | break; 38 | case 2: 39 | //Submenú 40 | printf("\n\t\tElige una opción [A-D]:\n"); 41 | printf("\t\tA.- Consulta de Saldo\n"); 42 | printf("\t\tB.- Pagar servicio\n"); 43 | printf("\t\tC.- Hablar con un ejecutivo\n"); 44 | printf("\t\tD.- Salir\n"); 45 | 46 | scanf("%s", &opcion2); //Pidiendo al usuario un dígito 47 | //fflush(stdin); 48 | //opcion2 = getchar(); 49 | switch(opcion2){ 50 | case 'A': 51 | printf("\t\t\tSaldo actual es de $250.00"); 52 | //break; 53 | case 'B': 54 | printf("\t\t\tPagando...."); 55 | printf("\n\t\t\tAdeudo actual es de $0.0"); 56 | //break; 57 | case 'C': 58 | printf("\t\t\tEspere en la línea"); 59 | //break; 60 | case 'D': 61 | printf("\n\t\t\tAgradecemos su llamada...pero estamos de vacaciones, ¡NO MOLESTE!"); 62 | //break; 63 | default: 64 | printf("\n\tElige una opción válida..."); 65 | //break; 66 | } 67 | //break; 68 | case 3: 69 | printf("\n\tBla bla bla bla bla bla..."); 70 | //TODO 71 | //break; 72 | //... 73 | //... 74 | case 4: 75 | printf("\n\tAgradecemos su llamada...pero estamos de vacaciones, ¡NO MOLESTE!"); 76 | //break; 77 | default: 78 | printf("\n\tElige una opción válida..."); 79 | //break; 80 | } //Fin switch 81 | // printf("\n\nDame una opción:"); 82 | // scanf("%d", &opcion); //Pidiendo al usuario un dígito 83 | }while(opcion != 4); //FIN do-while 84 | // }//FIN For 85 | 86 | printf("\nFuera del switch"); 87 | return 0; 88 | } 89 | ======= 90 | printf("Bienvenido a nuestro centro telefónico..bla bla bla..."); 91 | printf("\nElige una opción [1-4]:\n"); 92 | printf("\t1.- Quejas o sugerencias\n"); 93 | printf("\t2.- Pagos\n"); 94 | printf("\t3.- Revisar términos y condiciones\n"); 95 | printf("\t4.- Salir\n"); 96 | scanf("%d", &opcion); //Pidiendo al usuario un dígito 97 | 98 | switch(opcion){ //switch(1){...} 99 | case 1: 100 | printf("\n\tUno de nuestros agentes atenderá su caso, espere en la línea..."); 101 | break; 102 | case 2: 103 | //Submenú 104 | printf("\n\t\tElige una opción [A-D]:\n"); 105 | printf("\t\tA.- Consulta de Saldo\n"); 106 | printf("\t\tB.- Pagar servicio\n"); 107 | printf("\t\tC.- Hablar con un ejecutivo\n"); 108 | printf("\t\tD.- Salir\n"); 109 | 110 | scanf("%s", &opcion2); //Pidiendo al usuario un dígito 111 | //fflush(stdin); 112 | //opcion2 = getchar(); 113 | switch(opcion2){ 114 | case 'A': 115 | printf("\t\t\tSaldo actual es de $250.00"); 116 | break; 117 | case 'B': 118 | printf("\t\t\tPagando...."); 119 | printf("\n\t\t\tAdeudo actual es de $0.0"); 120 | break; 121 | case 'C': 122 | printf("\t\t\tEspere en la línea"); 123 | break; 124 | case 'D': 125 | printf("\n\t\t\tAgradecemos su llamada...pero estamos de vacaciones, ¡NO MOLESTE!"); 126 | break; 127 | default: 128 | printf("\n\tElige una opción válida..."); 129 | break; 130 | } 131 | break; 132 | case 3: 133 | printf("\n\tBla bla bla bla bla bla..."); 134 | //TODO 135 | break; 136 | //... 137 | //... 138 | case 4: 139 | printf("\n\tAgradecemos su llamada...pero estamos de vacaciones, ¡NO MOLESTE!"); 140 | break; 141 | default: 142 | printf("\n\tElige una opción válida..."); 143 | break; 144 | } 145 | printf("\nFuera del switch"); 146 | return 0; 147 | } 148 | >>>>>>> 1b80eaa5d12a3ba1683bd1d32aa3c902b054fed6 149 | -------------------------------------------------------------------------------- /exercises/promedio.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | Descripcion: Calcular promedio de un alumno o alumna 4 | */ 5 | 6 | char nomMateria; //Variable Global 7 | double promedio = 0; 8 | 9 | int main(){ 10 | int cont, opt; 11 | double calificaciones[10] ={ 9, 5, 5, 10}; 12 | char nombres[20][20]; 13 | printf("\nCuantas calificaciones deseas ingresar: "); 14 | scanf("%i", &opt); 15 | 16 | //Guardar Calificaciones 17 | for(cont = 0; cont < opt; cont++){ // 18 | printf("\n-----------------------------"); 19 | printf("\nDame la asignatura : "); 20 | scanf("%s", nombres[cont]); //nombres = ['I', 'n', 'g', 'l', 'e', 's', '\0', '\0'] 21 | 22 | printf("\nDame la calificacion : "); 23 | scanf("%lf", &calificaciones[cont]); //calificaciones[0] = 10, calificaciones[1] = 9 24 | 25 | printf("Calificacion: %0.2lf\n", calificaciones[cont]); //calificaciones[0] = 10 calificaciones[1] = 9 26 | promedio += calificaciones[cont]; 27 | } 28 | printf("\tPromedio: %0.2f\n", promedio/opt); 29 | 30 | //Consultar Calificaciones 31 | printf("\nDame una posición: "); 32 | scanf("%i", &opt); // 1 33 | 34 | printf("Asignatura: %s\n", nombres[opt-1]); //calificaciones[0] = 10 calificaciones[1] = 9 35 | printf("Calificación: %0.2lf\n", calificaciones[opt-1]); //calificaciones[0] = 10 calificaciones[1] = 9 36 | 37 | printf("Fin de programa"); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /exercises/struct_anidadoV2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | Iterar 6 | Meter arreglos 7 | */ 8 | 9 | struct info{ 10 | char nombre[25]; 11 | char apPaterno[25]; 12 | char apMaterno[25]; 13 | char direccion[25]; 14 | }; 15 | 16 | struct academico{ 17 | char numeroEmpleado[13]; 18 | struct info datos_profesor; 19 | }profesor[5]; 20 | 21 | struct alumnado{ 22 | char numeroCuenta[13]; 23 | char promedio[5]; 24 | struct info datos_estudiante; // 25 | }estudiante; 26 | 27 | //Función para remover el salto de línea final 28 | void remueveSaltoLinea (char *cadena){ 29 | char *saltoLinea; 30 | saltoLinea = strchr (cadena, '\n'); //Buscar un caracter en una cadena 31 | if (saltoLinea) 32 | *saltoLinea = ' '; //mitexto\n --- mitexto\0 33 | } 34 | 35 | int main(void){ 36 | int op, reg; 37 | 38 | do{ 39 | puts("¿Qué deseas capturar?"); 40 | puts("1.-\'Profesorado\'"); 41 | puts("2.-Alumnado"); 42 | puts("3.-Salir"); 43 | printf("Opción [1\\2\\3] :"); 44 | 45 | scanf("%i", &op); 46 | if(op == 1){ 47 | getchar(); 48 | puts("¿Cuántos registros deseas?"); 49 | scanf("%i", ®); 50 | for (int i=0; i 7 | #include 8 | 9 | int main() 10 | { 11 | FILE *archivo; 12 | char caracter; 13 | 14 | archivo = fopen("gente.txt","r"); 15 | 16 | if (archivo == NULL) 17 | { 18 | printf("\nError de apertura del archivo. \n\n"); 19 | } 20 | else 21 | { 22 | printf("\nEl contenido del archivo de prueba es \n\n"); 23 | while((caracter = fgetc(archivo)) != EOF){ //End Of File caracter = EOF != EOF 24 | printf("%c",caracter); //Daniel\n34...XEND 25 | } 26 | } 27 | fclose(archivo); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /files/read/fgets.c: -------------------------------------------------------------------------------- 1 | /* Lee cadenas de caracteres hasta n-1 caracteres o hasta que lea un cambio de línea '\n' o un final de archivo EOF. 2 | char *fgets(char *buffer, int tamaño, FILE *archivo); 3 | * */ 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | FILE *archivo; 11 | 12 | char caracteres[100]; 13 | 14 | archivo = fopen("gente.txt","r"); 15 | 16 | if (archivo == NULL) 17 | exit(1); 18 | else 19 | { 20 | printf("\nEl contenido del archivo de prueba es \n\n"); 21 | fflush(archivo); 22 | while (feof(archivo) == 0){ 23 | //fgets(salida, tamañoBuffer, entrada); 24 | fgets(caracteres,100, archivo); 25 | 26 | //fgets(persona[i].nombre, 60 , stdin); 27 | 28 | printf("%s\n",caracteres); 29 | } 30 | printf("\t%c",caracteres[0]); 31 | printf("\t%c",caracteres[1]); 32 | printf("\t%c",caracteres[2]); 33 | fflush(archivo); 34 | getchar(); 35 | } 36 | fclose(archivo); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /files/read/fread.c: -------------------------------------------------------------------------------- 1 | /*size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); 2 | 3 | Esta función lee un bloque de una "stream" de datos. 4 | Efectúa la lectura de un arreglo de elementos "count", cada uno de los cuales tiene un tamaño definido por "size". Luego los guarda en el bloque de memoria especificado por "ptr". El indicador de posición de la cadena de caracteres avanza hasta leer la totalidad de bytes.. 5 | 6 | 7 | PARAMETROS: 8 | ptr : Puntero a un bloque de memoria con un tamaño mínimo de (size*count) bytes. 9 | size : Tamaño en bytes de cada elemento (de los que voy a leer). 10 | count : Número de elementos. 11 | stream: Puntero a objetos FILE, que especifica la cadena de entrada. 12 | * 13 | * */ 14 | #include 15 | #include 16 | 17 | struct Estudiante{ 18 | int num; 19 | char nombre[25]; 20 | float promedio; 21 | }; 22 | 23 | int main(){ 24 | FILE *fp; 25 | char ch; 26 | struct Estudiante fca; 27 | 28 | fp = fopen("../write/FCA.txt","r"); //Statement 1 29 | 30 | if(fp == NULL){ 31 | printf("\nError."); 32 | exit(0); 33 | } 34 | 35 | printf("\n\tnum\tNombre\tPromedio\n"); 36 | 37 | while(fread(&fca,sizeof(fca),1,fp)>0) 38 | printf("\n\t%d\t%s\t%f\n",fca.num,fca.nombre,fca.promedio); 39 | fclose(fp); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /files/read/fscanf.c: -------------------------------------------------------------------------------- 1 | /*int fscanf(FILE *fichero, const char *formato, argumento, ...);*/ 2 | 3 | #include 4 | 5 | 6 | int main (){ 7 | FILE *fp; 8 | 9 | char buffer1[20]; 10 | char buffer2[20]; 11 | 12 | fp = fopen ( "gente.txt", "r" ); 13 | //fscanf(archivo, formatoSalida, buffer) 14 | fscanf(fp, "%s %s", buffer1, buffer2); 15 | printf("%s\n",buffer1); 16 | printf("%s\n",buffer2); 17 | 18 | fclose ( fp ); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /files/read/gente.txt: -------------------------------------------------------------------------------- 1 | Daniel 2 | 34CDMX 3 | Lalo 4 | 23CDMX -------------------------------------------------------------------------------- /files/write/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/files/write/a.out -------------------------------------------------------------------------------- /files/write/fwrite.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | //Decalaración de struct 5 | struct Estudiante{ 6 | int num; 7 | char nombre[25]; 8 | float promedio; 9 | }; 10 | 11 | int main(){ 12 | FILE *fp; // Declaración de archivo 13 | 14 | char ch; 15 | struct Estudiante fca; //Implementacmos struct 16 | 17 | fp = fopen("FCA.txt","w"); //Apertura del archivo 18 | //1.- Abrir el archivo 19 | //2.- Lectura / Escrituro 20 | //3.- Guardar 21 | //4.- Cerrar archivo 22 | 23 | if(fp == NULL){ 24 | printf("\nError."); 25 | exit(0); 26 | } 27 | 28 | do{ 29 | printf("\nNum Cuenta : "); 30 | scanf("%d",&fca.num); 31 | 32 | // fflush(stdin); 33 | puts("Nombre:"); 34 | scanf("%s",fca.nombre); 35 | 36 | printf("Promedio : "); 37 | scanf("%f",&fca.promedio); 38 | 39 | //fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) 40 | //ptr − Apuntador al arreglo de elementos que se escribiran. 41 | //size − Tamaño en bytes de cada elemento 42 | //nmemb − Numero de elementos 43 | //stream − Aputador al archivo donde se escribirá. 44 | fwrite(&fca, sizeof(fca), 1,fp); 45 | getchar(); 46 | 47 | printf("\nDeseas agrgar otro (s/n) : "); 48 | scanf("%c", &ch); 49 | }while(ch=='s' || ch=='S'); 50 | 51 | printf("\nEscribiendo archivo..."); 52 | 53 | fclose(fp); //Cierre de archivo 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /files/write/gente.doc: -------------------------------------------------------------------------------- 1 | adsadsa 2 | 23dasda 3 | dasdass 4 | 34dasdas 5 | dasdas 6 | 34sadas 7 | dasda 8 | 34sdasd 9 | Daniel 10 | 34CDMX 11 | Jesus 12 | 43CDMX 13 | -------------------------------------------------------------------------------- /files/write/gente.txt: -------------------------------------------------------------------------------- 1 | Juan 2 | 34CDMX 3 | Laura 4 | 12CDMX 5 | dasda 6 | 34dasd 7 | asdsa 8 | 34dasd 9 | dasdas 10 | 34sdasd 11 | 4545 12 | 54dsad 13 | dasdasd 14 | 34dasdas 15 | sdas 16 | 343dasdas 17 | -------------------------------------------------------------------------------- /files/write/write.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | struct datos{ 6 | char nombre[60]; 7 | int edad; 8 | char ciudad[20]; 9 | }persona[3]; 10 | 11 | // Array de struct con datos para 3 personas. 12 | 13 | /*Files*/ 14 | 15 | /* 16 | * "r (read)" : abrir un archivo para lectura, el archivo debe existir. 17 | * "w (write) : abrir un archivo para escritura, se crea si no existe o se sobreescribe si existe. 18 | * "a (append)" : abrir un archivo para escritura al final del contenido, si no existe se crea. 19 | * "r+ (read+)" : abrir un archivo para lectura y escritura, el archivo debe existir. 20 | * "w+ (write+)" : crear un archivo para lectura y escritura, se crea si no existe o se sobreescribe si existe. 21 | * "r+b ó rb+ (binary)" : Abre un archivo en modo binario para actualización (lectura y escritura). 22 | * "rb (binary)" : Abre un archivo en modo binario para lectura. 23 | */ 24 | 25 | //ESCRITURA DE ARCHIVO 26 | 27 | FILE *archivo; //Declaración de archivo 28 | int i, numero=0; //Variables 29 | 30 | // identificador = fopen("locacionArchivo", "ModoDeApertura"); 31 | archivo = fopen("../gente.rtf", "a"); //ABRIR EL ARCHIVO 32 | if (archivo == NULL) // Si no existe 33 | printf("No se pudo abrir el archivo :(\n"); 34 | else{ 35 | for (i=0; i<2; i++){ //Pide datos de 2 personas y los guarda en el archivo. 36 | puts("Nombre:"); 37 | fgets(persona[i].nombre, 60 , stdin); //Guardando en struct RAM 38 | //Escribir en archivos con fprintf 39 | fprintf(archivo, "%s", persona[i].nombre); //Impresión en archivo DD 40 | // fprintf(destino, formato, origen); 41 | puts("Edad:"); 42 | scanf("%d", &persona[i].edad); //Guardando en struct 43 | getchar(); //Pausa 44 | 45 | //Escribir en archivos con fprintf 46 | fprintf(archivo, "%d", persona[i].edad); 47 | 48 | puts("Ciudad:"); 49 | fgets(persona[i].ciudad, 20 , stdin); 50 | //Escribir en archivos con fputs 51 | fputs(persona[i].ciudad, archivo); // Escribir Archivo 52 | 53 | } 54 | } 55 | fclose(archivo); //Cerrar archivo 56 | 57 | // LECTURA DE ARCHIVO 58 | 59 | /* archivo = fopen("gente", "r"); 60 | if (archivo == NULL) 61 | printf("No se pudo abrir el archivo.\n"); 62 | else 63 | { */ 64 | do 65 | { 66 | puts("Escriba el número de registro que desea a leer[1-2]:\n" 67 | "(Para salir presione 0)."); 68 | scanf("%d", &numero); 69 | for (i=0; i 3 | 4 | int edad, e; 5 | //Declaración e implementación de función 6 | void saluda(void){ 7 | printf("Hola\n"); 8 | } 9 | void despidete(void){ 10 | printf("Adios\n"); 11 | } 12 | 13 | float calculaEdad(int anio){ 14 | //printf("Naciste el anio %d\n", anio); 15 | edad = 2021 - anio; 16 | return edad; 17 | } 18 | 19 | 20 | int main(void){ 21 | for(int x=0; x<100 ; x++){ 22 | printf("\nIteración %d:", x); 23 | saluda(); 24 | } 25 | 26 | despidete(); 27 | //e = calculaEdad(1990); //23 28 | printf("Tienes %f anios", calculaEdad(1990) ); 29 | return 0; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /function/ejemplo_funcion.c: -------------------------------------------------------------------------------- 1 | #include //Cabcera 2 | //valorRetorno identificador(tipoDato parametro, tipoDato parametro2...); 3 | //int suma(int entero1, int entero2); //Declaración de función 4 | 5 | int resultado; 6 | 7 | int sumaTres(int entero1, int entero2, int entero3){ //Implementación de función int suma(entero = 200, entero2 =15) 8 | int resultado = 0; //Variable local 9 | resultado = entero1 + entero2 + entero3; // resultado = 200 + 15 -> 215 10 | return resultado; // resultado 215; 11 | } 12 | 13 | int sumaDos(int entero1, int entero2){ //Implementación de función int suma(entero = 200, entero2 =15) 14 | int resultado = 0; //Variable local 15 | resultado = entero1 + entero2; // resultado = 200 + 15 -> 215 16 | return resultado; // resultado 215; 17 | } 18 | 19 | int sumaCuatro(int entero1, int entero2, int entero3, int entero4){ //Implementación de función int suma(entero = 200, entero2 =15) 20 | int resultado = 0; //Variable local 21 | resultado = entero1 + entero2 + entero3 + entero4; // resultado = 200 + 15 -> 215 22 | printf("El resultado de la cuarta suma DENTRO DE LA FUNCIÓN es: %d\n", resultado); //2do. 23 | return resultado; // resultado 30; 24 | } 25 | void main() { 26 | 27 | //resultado = (sumaDos(1,500) + 3)/5; 28 | 29 | //printf("El resultado de la primera suma es: %d\n", sumaTres(200,15, 10)); 30 | //printf("El resultado de la segunda suma es: %d\n", resultado); 31 | //printf("El resultado de la tercera suma es: %d\n", sumaDos(1000,1500)); 32 | sumaCuatro(10,500,1,125); // 1ra 33 | printf("El resultado de la cuarta suma FUERA DE LA FUNCIÓN es: %d\n", sumaCuatro(10,15,1,4)); 34 | //printf("Valor de resultado %d", resultado); 35 | return; 36 | } -------------------------------------------------------------------------------- /function/ejemplo_funciones.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include // Boolean 3 | 4 | bool COvid = true; 5 | int cuarentena = 5; 6 | 7 | void come(); //Declaración de función 8 | void duerme(); 9 | void codifica(); 10 | void quedateEnCasa(int x); 11 | 12 | int main(){ 13 | while(COvid != false){ // true != false => true 14 | for(int x=1; x<=cuarentena; x++){ 15 | printf("-----------------"); 16 | printf("\t\nDía %d\n", x); 17 | quedateEnCasa(x); 18 | } 19 | COvid = false; 20 | } 21 | return 0; 22 | } 23 | 24 | //Implementación de las funciones 25 | void come(){ 26 | printf("Come sanamente\n"); 27 | return; 28 | } 29 | void duerme(){ 30 | printf("Duerme 8 horas\n"); 31 | return; 32 | } 33 | void codifica(){ //Implementación de función 34 | printf("Programa just 4fun\n"); 35 | return; 36 | } 37 | void quedateEnCasa(int dia){ //Implementación de función 38 | if(dia <= 5){ 39 | printf("Fase 1\n"); 40 | } 41 | else if(dia >5 && dia <=15){ 42 | printf("Fase 2\n"); 43 | } 44 | else{ 45 | printf("Fase 3\n"); 46 | } 47 | come(); 48 | duerme(); 49 | codifica(); 50 | return; 51 | } 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /function/funciones.h: -------------------------------------------------------------------------------- 1 | int suma(int entero1, int entero2){ //Implementación de función int suma(entero = 200, entero2 =15) 2 | int resultado = 0; //Variable local 3 | resultado = entero1 + entero2; // resultado = 200 + 15 -> 215 4 | return resultado; // resultado 215; 5 | } -------------------------------------------------------------------------------- /function/function: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/function/function -------------------------------------------------------------------------------- /function/function.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //tipodato identificador(parametros){ 4 | 5 | //} 6 | void saludo(void){ //Declarando e Implementando la función 7 | printf("\tHola Mundo\n"); /* imprime la cadena */ 8 | return; /* sale de la función */ 9 | } 10 | 11 | void despedida(){ //Declarando e Implementando la función 12 | printf("\tAdios\n"); /* imprime la cadena */ 13 | return; /* sale de la función */ 14 | } 15 | 16 | int main(){ /* Función principal del programa */ 17 | printf("Printf antes de la función\n"); 18 | for(int x=0; x <10; x++){ 19 | saludo(); /* llamada a la función saludo*/ 20 | despedida(); 21 | } 22 | saludo(); 23 | printf("Printf después de la función\n"); 24 | despedida(); 25 | return 0; /* sale del programa con código 0 (correcto) */ 26 | } -------------------------------------------------------------------------------- /function/function_param.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int resultadoResta = 0; //Variable Global 4 | 5 | int sumar(int n1, int n2){ 6 | //int resultado = n1 + n2; 7 | return n1 + n2; // return 20 + 230; --> return 250; 8 | } 9 | 10 | int restar(int numero1, int numero2){ 11 | resultadoResta = numero1 - numero2; 12 | printf("\nResultado RESTA desde dentro de la función %d", resultadoResta); 13 | return resultadoResta; 14 | } 15 | 16 | int main(void){ 17 | 18 | int suma = sumar(20, 230); /* Se ejecuta correctamente*/ 19 | /*printf("La suma de %d + %d es: %d\n ",n1, n2, suma);*/ 20 | printf("La suma es: %d\n ", suma); 21 | int resta = restar(100, 50); // 50 22 | printf("\nResultado RESTA desde fuera de la función: %d\n ", resta); 23 | printf("\nVariable resutadoResta: %d\n ", resultadoResta); 24 | //int resta = restar(1150, 230); 25 | /*printf("La resta de %d - %d es: %d ", numero2, numero1, suma);*/ 26 | //printf("La resta es: %d\n ", resta); 27 | int resultadoFinal = suma - resta; 28 | printf("\nBalance final suma - resta = %d", resultadoFinal); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /function/function_recursive: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/function/function_recursive -------------------------------------------------------------------------------- /function/function_recursive.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /*valor_retorno nombreFunción (parámetros de entrada){ 4 | //TODO 5 | }*/ 6 | 7 | /*Pendientes: 8 | 1.- Utilizar un tipo de dato más grande 9 | 2.- Validar entrada a solo enteros positivos 10 | */ 11 | 12 | //5 * 4 * 3 * 2 * 1 = 5! 13 | 14 | long factorial(int n){ //int n = 0; 15 | 16 | long res; 17 | 18 | if (n == 0){ /* caso base */ // 0 == 0 -> false 19 | return 1; 20 | }else{ 21 | res = n * factorial (n - 1); 22 | printf("\n\tFactorial de %i = %li",n, res); 23 | return res; /* llamada a esta misma función */ 24 | //120 25 | } 26 | } 27 | 28 | int main(void){ 29 | factorial(3); // = 5 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /function/function_recursive_mutuo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/function/function_recursive_mutuo -------------------------------------------------------------------------------- /function/function_referencia.c: -------------------------------------------------------------------------------- 1 | /*El paso por referencia se hace utilizando apuntadores. Se envía la dirección de memoria de la variable, por lo tanto los cambios que haga la función si afectan el valor de la variable*/ 2 | #include 3 | 4 | int var1 = 57; /* definimos numero con valor de 57*/ 5 | //int var2 = 100; 6 | //void sumar_referencia(57){ 7 | // 57 += 1; --> 58 8 | // printf(58); 9 | //} 10 | // 57 11 | 12 | void sumar_referencia(int *numero){ //RETURN_TYPE name_of_function ( PARAMETER_TYPE name_of_param,PARAMETER_TYPE name_of_param, etc); 13 | 14 | 15 | printf("\nDir de var1: %p\n", &var1); /*0x560bafb28030*/ 16 | printf("Dir de numero: %p\n", &numero); /*0x560bafb28030*/ 17 | 18 | // int *numero = "0x560bafb28030"; 19 | *numero += 1; /* 57 le sumamos 1 al numero */ 20 | // num = 57 + 1; 21 | printf("\n2.- Valor de numero dentro sumar_referencia() es: %d\n", *numero); 22 | return; 23 | } 24 | 25 | int main(void){ 26 | 27 | 28 | printf("1.- Valor original de numero es: %d", var1); 29 | // sumar_referencia(0x55667f398030); 30 | sumar_referencia(&var1); /* enviamos numero a la función */ 31 | /* sumar_referencia(0x560bafb28030); */ 32 | printf("\n3.- Valor de numero dentro de main() es: %d\n", var1); 33 | /* podemos notar que el valor de numero se modifica 34 | * y que ahora dentro de main() también se ha modificado 35 | * aunque la función no haya retornado ningún valor. 36 | */ 37 | return 0; 38 | } -------------------------------------------------------------------------------- /function/function_valor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/function/function_valor -------------------------------------------------------------------------------- /function/function_valor.c: -------------------------------------------------------------------------------- 1 | /*El paso por valor envía una copia de los parámetros a la función por lo tanto los cambios que se hagan en ella no son tomados en cuenta dentro de la función main()*/ 2 | #include 3 | 4 | //Declarando e Implementando Función 5 | 6 | int numero = 57; // Asignación de valor 7 | 8 | void sumar_valor(int num){ //57 --> num --> int num = 57; 9 | num++; /* 58 num = num +1; -> num = 57 + 1 -> num= 58; */ 10 | printf("2.- Valor de numero dentro sumar_valor() es: %d\n", num); //58 11 | return; 12 | } 13 | 14 | int main(){ 15 | printf("1.- El valor original de numero: %d\n", numero); 16 | sumar_valor(numero); /* enviamos numero a la función */ 17 | /*sumar_valor(57);*/ 18 | printf("3.- Valor de numero dentro de main() es: %d\n", numero); // 57 19 | /* podemos notar que el valor de numero se modifica 20 | * sólo dentro de la función sumar_valor pero en la principal 21 | */ 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /function/mutual_recursive_function.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | * Description: Recorre el abecedario 4 | * Authors: Taller Extracurricular Programación 5 | */ 6 | 7 | //Declaración de funciones 8 | //tipoDatoRetorno identificador(valoresEntrada); 9 | 10 | void funcionTutorA(char num); 11 | void funcionTutorB(char num); 12 | 13 | //Función principal(main) 14 | int main(void){ 15 | printf("\nImprimiendo abecedario\n"); 16 | funcionTutorA('A'); //invocación de función 17 | printf("\nFin Programa\n\n"); 18 | return 0; 19 | } 20 | 21 | //Implementación de funciones 22 | void funcionTutorA(char num){ //char num = 'Z'; 'Y' 'X' ....'B' 'A' 23 | //TODO 24 | if (num < 'Z'){ // if ('@' < 'Z'){ TODO } --> 65 < 90 --> true 25 | funcionTutorB(num); //funB('Z'); funB('Y') funB('X') funB('B') 26 | } 27 | printf("%c ,", num); // 'A' ...'B', 'C'....'Z' 28 | } 29 | void funcionTutorB(char num){ // char num = 'A' 30 | funcionTutorA(++num); // funA('@'); funA('X') funA('W') ... funA('A') 31 | } -------------------------------------------------------------------------------- /function/variables_globales.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //Declaración de variables globales 4 | int entero1 = 3; 5 | int entero2 = 30; 6 | int resultado = 0; 7 | 8 | int suma(){ //Declaración e implementación de función 9 | entero1 = 10; 10 | entero2 = 5; 11 | resultado = entero1 + entero2; 12 | printf("2.- El resultado de la suma fuera de la funcion es: %d\n", resultado); 13 | return resultado; 14 | // return 33; 15 | } 16 | 17 | int main() { 18 | resultado = entero1 + entero2; 19 | printf("1.- El resultado de la suma fuera de la funcion es: %d\n", resultado); 20 | printf("3.- El resultado de la suma en la funcion es: %d\n", suma()); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /function/variables_locales.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int suma(); //Declaración de función 4 | 5 | int main() { 6 | printf("FUERA DE LA FUNCIÓN: El resultado de la suma es: %d\n", suma()); 7 | // printf("El resultado de %d + %d es: %d\n", entero1, entero2, suma()); 8 | return 0; 9 | } 10 | 11 | int suma(){ //Implementación de función 12 | int entero1 = 3; //Variables locales 13 | int entero2 = 30; 14 | int resultado = 0; 15 | resultado = entero1 + entero2; 16 | printf("Dentro de la FUNCIÓN: El resultado de %d + %d es: %d\n", entero1, entero2, resultado); 17 | return resultado; 18 | } 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /introduction/Hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/introduction/Hello -------------------------------------------------------------------------------- /introduction/MiHolamundo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/introduction/MiHolamundo -------------------------------------------------------------------------------- /introduction/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/introduction/a.out -------------------------------------------------------------------------------- /introduction/area: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/introduction/area -------------------------------------------------------------------------------- /introduction/area.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define PI 3.141516 3 | 4 | int main(){ //Funcion principal 5 | //Variables 6 | //tipoDato identificador; 7 | 8 | float area; //3.14, 0.10, 0.0000001 10.0 9 | float radio; //Declaracion variables 10 | //float PI = 3.1416; 11 | 12 | radio = 5; //Asignacion de valores 13 | area = PI * (radio * radio); //Operacion 14 | //area = 3.1416 * (5 * 5); 15 | 16 | printf("Area\n"); //Impresion 17 | printf("%s%f\n\n", "Area de Circulo con radio 5:", area); //Impresion 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /introduction/area.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/introduction/area.o -------------------------------------------------------------------------------- /introduction/area.pp: -------------------------------------------------------------------------------- 1 | # 0 "area.c" 2 | # 0 "" 3 | # 0 "" 4 | # 1 "/usr/include/stdc-predef.h" 1 3 4 5 | # 0 "" 2 6 | # 1 "area.c" 7 | # 1 "/usr/include/stdio.h" 1 3 4 8 | # 27 "/usr/include/stdio.h" 3 4 9 | # 1 "/usr/include/bits/libc-header-start.h" 1 3 4 10 | # 33 "/usr/include/bits/libc-header-start.h" 3 4 11 | # 1 "/usr/include/features.h" 1 3 4 12 | # 473 "/usr/include/features.h" 3 4 13 | # 1 "/usr/include/sys/cdefs.h" 1 3 4 14 | # 462 "/usr/include/sys/cdefs.h" 3 4 15 | # 1 "/usr/include/bits/wordsize.h" 1 3 4 16 | # 463 "/usr/include/sys/cdefs.h" 2 3 4 17 | # 1 "/usr/include/bits/long-double.h" 1 3 4 18 | # 464 "/usr/include/sys/cdefs.h" 2 3 4 19 | # 474 "/usr/include/features.h" 2 3 4 20 | # 497 "/usr/include/features.h" 3 4 21 | # 1 "/usr/include/gnu/stubs.h" 1 3 4 22 | # 10 "/usr/include/gnu/stubs.h" 3 4 23 | # 1 "/usr/include/gnu/stubs-64.h" 1 3 4 24 | # 11 "/usr/include/gnu/stubs.h" 2 3 4 25 | # 498 "/usr/include/features.h" 2 3 4 26 | # 34 "/usr/include/bits/libc-header-start.h" 2 3 4 27 | # 28 "/usr/include/stdio.h" 2 3 4 28 | 29 | 30 | 31 | 32 | 33 | # 1 "/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/stddef.h" 1 3 4 34 | # 209 "/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/stddef.h" 3 4 35 | 36 | # 209 "/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/stddef.h" 3 4 37 | typedef long unsigned int size_t; 38 | # 34 "/usr/include/stdio.h" 2 3 4 39 | 40 | 41 | # 1 "/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/stdarg.h" 1 3 4 42 | # 40 "/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/stdarg.h" 3 4 43 | typedef __builtin_va_list __gnuc_va_list; 44 | # 37 "/usr/include/stdio.h" 2 3 4 45 | 46 | # 1 "/usr/include/bits/types.h" 1 3 4 47 | # 27 "/usr/include/bits/types.h" 3 4 48 | # 1 "/usr/include/bits/wordsize.h" 1 3 4 49 | # 28 "/usr/include/bits/types.h" 2 3 4 50 | # 1 "/usr/include/bits/timesize.h" 1 3 4 51 | # 29 "/usr/include/bits/types.h" 2 3 4 52 | 53 | 54 | typedef unsigned char __u_char; 55 | typedef unsigned short int __u_short; 56 | typedef unsigned int __u_int; 57 | typedef unsigned long int __u_long; 58 | 59 | 60 | typedef signed char __int8_t; 61 | typedef unsigned char __uint8_t; 62 | typedef signed short int __int16_t; 63 | typedef unsigned short int __uint16_t; 64 | typedef signed int __int32_t; 65 | typedef unsigned int __uint32_t; 66 | 67 | typedef signed long int __int64_t; 68 | typedef unsigned long int __uint64_t; 69 | 70 | 71 | 72 | 73 | 74 | 75 | typedef __int8_t __int_least8_t; 76 | typedef __uint8_t __uint_least8_t; 77 | typedef __int16_t __int_least16_t; 78 | typedef __uint16_t __uint_least16_t; 79 | typedef __int32_t __int_least32_t; 80 | typedef __uint32_t __uint_least32_t; 81 | typedef __int64_t __int_least64_t; 82 | typedef __uint64_t __uint_least64_t; 83 | 84 | 85 | 86 | typedef long int __quad_t; 87 | typedef unsigned long int __u_quad_t; 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | typedef long int __intmax_t; 96 | typedef unsigned long int __uintmax_t; 97 | # 141 "/usr/include/bits/types.h" 3 4 98 | # 1 "/usr/include/bits/typesizes.h" 1 3 4 99 | # 142 "/usr/include/bits/types.h" 2 3 4 100 | # 1 "/usr/include/bits/time64.h" 1 3 4 101 | # 143 "/usr/include/bits/types.h" 2 3 4 102 | 103 | 104 | typedef unsigned long int __dev_t; 105 | typedef unsigned int __uid_t; 106 | typedef unsigned int __gid_t; 107 | typedef unsigned long int __ino_t; 108 | typedef unsigned long int __ino64_t; 109 | typedef unsigned int __mode_t; 110 | typedef unsigned long int __nlink_t; 111 | typedef long int __off_t; 112 | typedef long int __off64_t; 113 | typedef int __pid_t; 114 | typedef struct { int __val[2]; } __fsid_t; 115 | typedef long int __clock_t; 116 | typedef unsigned long int __rlim_t; 117 | typedef unsigned long int __rlim64_t; 118 | typedef unsigned int __id_t; 119 | typedef long int __time_t; 120 | typedef unsigned int __useconds_t; 121 | typedef long int __suseconds_t; 122 | typedef long int __suseconds64_t; 123 | 124 | typedef int __daddr_t; 125 | typedef int __key_t; 126 | 127 | 128 | typedef int __clockid_t; 129 | 130 | 131 | typedef void * __timer_t; 132 | 133 | 134 | typedef long int __blksize_t; 135 | 136 | 137 | 138 | 139 | typedef long int __blkcnt_t; 140 | typedef long int __blkcnt64_t; 141 | 142 | 143 | typedef unsigned long int __fsblkcnt_t; 144 | typedef unsigned long int __fsblkcnt64_t; 145 | 146 | 147 | typedef unsigned long int __fsfilcnt_t; 148 | typedef unsigned long int __fsfilcnt64_t; 149 | 150 | 151 | typedef long int __fsword_t; 152 | 153 | typedef long int __ssize_t; 154 | 155 | 156 | typedef long int __syscall_slong_t; 157 | 158 | typedef unsigned long int __syscall_ulong_t; 159 | 160 | 161 | 162 | typedef __off64_t __loff_t; 163 | typedef char *__caddr_t; 164 | 165 | 166 | typedef long int __intptr_t; 167 | 168 | 169 | typedef unsigned int __socklen_t; 170 | 171 | 172 | 173 | 174 | typedef int __sig_atomic_t; 175 | # 39 "/usr/include/stdio.h" 2 3 4 176 | # 1 "/usr/include/bits/types/__fpos_t.h" 1 3 4 177 | 178 | 179 | 180 | 181 | # 1 "/usr/include/bits/types/__mbstate_t.h" 1 3 4 182 | # 13 "/usr/include/bits/types/__mbstate_t.h" 3 4 183 | typedef struct 184 | { 185 | int __count; 186 | union 187 | { 188 | unsigned int __wch; 189 | char __wchb[4]; 190 | } __value; 191 | } __mbstate_t; 192 | # 6 "/usr/include/bits/types/__fpos_t.h" 2 3 4 193 | 194 | 195 | 196 | 197 | typedef struct _G_fpos_t 198 | { 199 | __off_t __pos; 200 | __mbstate_t __state; 201 | } __fpos_t; 202 | # 40 "/usr/include/stdio.h" 2 3 4 203 | # 1 "/usr/include/bits/types/__fpos64_t.h" 1 3 4 204 | # 10 "/usr/include/bits/types/__fpos64_t.h" 3 4 205 | typedef struct _G_fpos64_t 206 | { 207 | __off64_t __pos; 208 | __mbstate_t __state; 209 | } __fpos64_t; 210 | # 41 "/usr/include/stdio.h" 2 3 4 211 | # 1 "/usr/include/bits/types/__FILE.h" 1 3 4 212 | 213 | 214 | 215 | struct _IO_FILE; 216 | typedef struct _IO_FILE __FILE; 217 | # 42 "/usr/include/stdio.h" 2 3 4 218 | # 1 "/usr/include/bits/types/FILE.h" 1 3 4 219 | 220 | 221 | 222 | struct _IO_FILE; 223 | 224 | 225 | typedef struct _IO_FILE FILE; 226 | # 43 "/usr/include/stdio.h" 2 3 4 227 | # 1 "/usr/include/bits/types/struct_FILE.h" 1 3 4 228 | # 35 "/usr/include/bits/types/struct_FILE.h" 3 4 229 | struct _IO_FILE; 230 | struct _IO_marker; 231 | struct _IO_codecvt; 232 | struct _IO_wide_data; 233 | 234 | 235 | 236 | 237 | typedef void _IO_lock_t; 238 | 239 | 240 | 241 | 242 | 243 | struct _IO_FILE 244 | { 245 | int _flags; 246 | 247 | 248 | char *_IO_read_ptr; 249 | char *_IO_read_end; 250 | char *_IO_read_base; 251 | char *_IO_write_base; 252 | char *_IO_write_ptr; 253 | char *_IO_write_end; 254 | char *_IO_buf_base; 255 | char *_IO_buf_end; 256 | 257 | 258 | char *_IO_save_base; 259 | char *_IO_backup_base; 260 | char *_IO_save_end; 261 | 262 | struct _IO_marker *_markers; 263 | 264 | struct _IO_FILE *_chain; 265 | 266 | int _fileno; 267 | int _flags2; 268 | __off_t _old_offset; 269 | 270 | 271 | unsigned short _cur_column; 272 | signed char _vtable_offset; 273 | char _shortbuf[1]; 274 | 275 | _IO_lock_t *_lock; 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | __off64_t _offset; 284 | 285 | struct _IO_codecvt *_codecvt; 286 | struct _IO_wide_data *_wide_data; 287 | struct _IO_FILE *_freeres_list; 288 | void *_freeres_buf; 289 | size_t __pad5; 290 | int _mode; 291 | 292 | char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; 293 | }; 294 | # 44 "/usr/include/stdio.h" 2 3 4 295 | # 52 "/usr/include/stdio.h" 3 4 296 | typedef __gnuc_va_list va_list; 297 | # 63 "/usr/include/stdio.h" 3 4 298 | typedef __off_t off_t; 299 | # 77 "/usr/include/stdio.h" 3 4 300 | typedef __ssize_t ssize_t; 301 | 302 | 303 | 304 | 305 | 306 | 307 | typedef __fpos_t fpos_t; 308 | # 133 "/usr/include/stdio.h" 3 4 309 | # 1 "/usr/include/bits/stdio_lim.h" 1 3 4 310 | # 134 "/usr/include/stdio.h" 2 3 4 311 | 312 | 313 | 314 | extern FILE *stdin; 315 | extern FILE *stdout; 316 | extern FILE *stderr; 317 | 318 | 319 | 320 | 321 | 322 | 323 | extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__)); 324 | 325 | extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__)); 326 | 327 | 328 | 329 | extern int renameat (int __oldfd, const char *__old, int __newfd, 330 | const char *__new) __attribute__ ((__nothrow__ , __leaf__)); 331 | # 173 "/usr/include/stdio.h" 3 4 332 | extern FILE *tmpfile (void) ; 333 | # 187 "/usr/include/stdio.h" 3 4 334 | extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; 335 | 336 | 337 | 338 | 339 | extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; 340 | # 204 "/usr/include/stdio.h" 3 4 341 | extern char *tempnam (const char *__dir, const char *__pfx) 342 | __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ; 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | extern int fclose (FILE *__stream); 351 | 352 | 353 | 354 | 355 | extern int fflush (FILE *__stream); 356 | # 227 "/usr/include/stdio.h" 3 4 357 | extern int fflush_unlocked (FILE *__stream); 358 | # 246 "/usr/include/stdio.h" 3 4 359 | extern FILE *fopen (const char *__restrict __filename, 360 | const char *__restrict __modes) ; 361 | 362 | 363 | 364 | 365 | extern FILE *freopen (const char *__restrict __filename, 366 | const char *__restrict __modes, 367 | FILE *__restrict __stream) ; 368 | # 279 "/usr/include/stdio.h" 3 4 369 | extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ; 370 | # 292 "/usr/include/stdio.h" 3 4 371 | extern FILE *fmemopen (void *__s, size_t __len, const char *__modes) 372 | __attribute__ ((__nothrow__ , __leaf__)) ; 373 | 374 | 375 | 376 | 377 | extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__)) ; 378 | 379 | 380 | 381 | 382 | 383 | extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)); 384 | 385 | 386 | 387 | extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, 388 | int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); 389 | 390 | 391 | 392 | 393 | extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, 394 | size_t __size) __attribute__ ((__nothrow__ , __leaf__)); 395 | 396 | 397 | extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | extern int fprintf (FILE *__restrict __stream, 406 | const char *__restrict __format, ...); 407 | 408 | 409 | 410 | 411 | extern int printf (const char *__restrict __format, ...); 412 | 413 | extern int sprintf (char *__restrict __s, 414 | const char *__restrict __format, ...) __attribute__ ((__nothrow__)); 415 | 416 | 417 | 418 | 419 | 420 | extern int vfprintf (FILE *__restrict __s, const char *__restrict __format, 421 | __gnuc_va_list __arg); 422 | 423 | 424 | 425 | 426 | extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); 427 | 428 | extern int vsprintf (char *__restrict __s, const char *__restrict __format, 429 | __gnuc_va_list __arg) __attribute__ ((__nothrow__)); 430 | 431 | 432 | 433 | extern int snprintf (char *__restrict __s, size_t __maxlen, 434 | const char *__restrict __format, ...) 435 | __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4))); 436 | 437 | extern int vsnprintf (char *__restrict __s, size_t __maxlen, 438 | const char *__restrict __format, __gnuc_va_list __arg) 439 | __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0))); 440 | # 379 "/usr/include/stdio.h" 3 4 441 | extern int vdprintf (int __fd, const char *__restrict __fmt, 442 | __gnuc_va_list __arg) 443 | __attribute__ ((__format__ (__printf__, 2, 0))); 444 | extern int dprintf (int __fd, const char *__restrict __fmt, ...) 445 | __attribute__ ((__format__ (__printf__, 2, 3))); 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | extern int fscanf (FILE *__restrict __stream, 454 | const char *__restrict __format, ...) ; 455 | 456 | 457 | 458 | 459 | extern int scanf (const char *__restrict __format, ...) ; 460 | 461 | extern int sscanf (const char *__restrict __s, 462 | const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__)); 463 | 464 | 465 | 466 | 467 | 468 | # 1 "/usr/include/bits/floatn.h" 1 3 4 469 | # 119 "/usr/include/bits/floatn.h" 3 4 470 | # 1 "/usr/include/bits/floatn-common.h" 1 3 4 471 | # 24 "/usr/include/bits/floatn-common.h" 3 4 472 | # 1 "/usr/include/bits/long-double.h" 1 3 4 473 | # 25 "/usr/include/bits/floatn-common.h" 2 3 4 474 | # 120 "/usr/include/bits/floatn.h" 2 3 4 475 | # 407 "/usr/include/stdio.h" 2 3 4 476 | 477 | 478 | 479 | extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf") 480 | 481 | ; 482 | extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf") 483 | ; 484 | extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__)) 485 | 486 | ; 487 | # 435 "/usr/include/stdio.h" 3 4 488 | extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, 489 | __gnuc_va_list __arg) 490 | __attribute__ ((__format__ (__scanf__, 2, 0))) ; 491 | 492 | 493 | 494 | 495 | 496 | extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) 497 | __attribute__ ((__format__ (__scanf__, 1, 0))) ; 498 | 499 | 500 | extern int vsscanf (const char *__restrict __s, 501 | const char *__restrict __format, __gnuc_va_list __arg) 502 | __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0))); 503 | 504 | 505 | 506 | 507 | 508 | extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf") 509 | 510 | 511 | 512 | __attribute__ ((__format__ (__scanf__, 2, 0))) ; 513 | extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf") 514 | 515 | __attribute__ ((__format__ (__scanf__, 1, 0))) ; 516 | extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__)) 517 | 518 | 519 | 520 | __attribute__ ((__format__ (__scanf__, 2, 0))); 521 | # 489 "/usr/include/stdio.h" 3 4 522 | extern int fgetc (FILE *__stream); 523 | extern int getc (FILE *__stream); 524 | 525 | 526 | 527 | 528 | 529 | extern int getchar (void); 530 | 531 | 532 | 533 | 534 | 535 | 536 | extern int getc_unlocked (FILE *__stream); 537 | extern int getchar_unlocked (void); 538 | # 514 "/usr/include/stdio.h" 3 4 539 | extern int fgetc_unlocked (FILE *__stream); 540 | # 525 "/usr/include/stdio.h" 3 4 541 | extern int fputc (int __c, FILE *__stream); 542 | extern int putc (int __c, FILE *__stream); 543 | 544 | 545 | 546 | 547 | 548 | extern int putchar (int __c); 549 | # 541 "/usr/include/stdio.h" 3 4 550 | extern int fputc_unlocked (int __c, FILE *__stream); 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | extern int putc_unlocked (int __c, FILE *__stream); 559 | extern int putchar_unlocked (int __c); 560 | 561 | 562 | 563 | 564 | 565 | 566 | extern int getw (FILE *__stream); 567 | 568 | 569 | extern int putw (int __w, FILE *__stream); 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) 578 | __attribute__ ((__access__ (__write_only__, 1, 2))); 579 | # 608 "/usr/include/stdio.h" 3 4 580 | extern __ssize_t __getdelim (char **__restrict __lineptr, 581 | size_t *__restrict __n, int __delimiter, 582 | FILE *__restrict __stream) ; 583 | extern __ssize_t getdelim (char **__restrict __lineptr, 584 | size_t *__restrict __n, int __delimiter, 585 | FILE *__restrict __stream) ; 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | extern __ssize_t getline (char **__restrict __lineptr, 594 | size_t *__restrict __n, 595 | FILE *__restrict __stream) ; 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | extern int fputs (const char *__restrict __s, FILE *__restrict __stream); 604 | 605 | 606 | 607 | 608 | 609 | extern int puts (const char *__s); 610 | 611 | 612 | 613 | 614 | 615 | 616 | extern int ungetc (int __c, FILE *__stream); 617 | 618 | 619 | 620 | 621 | 622 | 623 | extern size_t fread (void *__restrict __ptr, size_t __size, 624 | size_t __n, FILE *__restrict __stream) ; 625 | 626 | 627 | 628 | 629 | extern size_t fwrite (const void *__restrict __ptr, size_t __size, 630 | size_t __n, FILE *__restrict __s); 631 | # 678 "/usr/include/stdio.h" 3 4 632 | extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, 633 | size_t __n, FILE *__restrict __stream) ; 634 | extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size, 635 | size_t __n, FILE *__restrict __stream); 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | extern int fseek (FILE *__stream, long int __off, int __whence); 644 | 645 | 646 | 647 | 648 | extern long int ftell (FILE *__stream) ; 649 | 650 | 651 | 652 | 653 | extern void rewind (FILE *__stream); 654 | # 712 "/usr/include/stdio.h" 3 4 655 | extern int fseeko (FILE *__stream, __off_t __off, int __whence); 656 | 657 | 658 | 659 | 660 | extern __off_t ftello (FILE *__stream) ; 661 | # 736 "/usr/include/stdio.h" 3 4 662 | extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); 663 | 664 | 665 | 666 | 667 | extern int fsetpos (FILE *__stream, const fpos_t *__pos); 668 | # 762 "/usr/include/stdio.h" 3 4 669 | extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 670 | 671 | extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 672 | 673 | extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 674 | 675 | 676 | 677 | extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 678 | extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 679 | extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | extern void perror (const char *__s); 688 | 689 | 690 | 691 | 692 | extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 693 | 694 | 695 | 696 | 697 | extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 698 | # 799 "/usr/include/stdio.h" 3 4 699 | extern FILE *popen (const char *__command, const char *__modes) ; 700 | 701 | 702 | 703 | 704 | 705 | extern int pclose (FILE *__stream); 706 | 707 | 708 | 709 | 710 | 711 | extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__)); 712 | # 839 "/usr/include/stdio.h" 3 4 713 | extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 714 | 715 | 716 | 717 | extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 718 | 719 | 720 | extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 721 | # 857 "/usr/include/stdio.h" 3 4 722 | extern int __uflow (FILE *); 723 | extern int __overflow (FILE *, int); 724 | # 874 "/usr/include/stdio.h" 3 4 725 | 726 | # 2 "area.c" 2 727 | 728 | 729 | 730 | # 4 "area.c" 731 | int main(){ 732 | 733 | 734 | 735 | float area; 736 | float radio; 737 | float 3.141516 = 3.1416; 738 | 739 | radio = 5; 740 | area = 3.141516 * (radio * radio); 741 | 742 | 743 | printf("Area\n"); 744 | printf("%s%f\n\n", "Area de Circulo con radio 5:", area); 745 | return 0; 746 | } 747 | -------------------------------------------------------------------------------- /introduction/area.s: -------------------------------------------------------------------------------- 1 | .file "area.c" 2 | .text 3 | .section .rodata 4 | .LC3: 5 | .string "Area" 6 | .LC4: 7 | .string "Area de Circulo con radio 5:" 8 | .LC5: 9 | .string "%s%f\n\n" 10 | .text 11 | .globl main 12 | .type main, @function 13 | main: 14 | .LFB0: 15 | .cfi_startproc 16 | pushq %rbp 17 | .cfi_def_cfa_offset 16 18 | .cfi_offset 6, -16 19 | movq %rsp, %rbp 20 | .cfi_def_cfa_register 6 21 | subq $16, %rsp 22 | movss .LC0(%rip), %xmm0 23 | movss %xmm0, -8(%rbp) 24 | pxor %xmm2, %xmm2 25 | cvtss2sd -8(%rbp), %xmm2 26 | movq %xmm2, %rax 27 | movsd .LC1(%rip), %xmm0 28 | movapd %xmm0, %xmm1 29 | movq %rax, %xmm0 30 | call pow@PLT 31 | movsd .LC2(%rip), %xmm1 32 | mulsd %xmm1, %xmm0 33 | cvtsd2ss %xmm0, %xmm0 34 | movss %xmm0, -4(%rbp) 35 | leaq .LC3(%rip), %rax 36 | movq %rax, %rdi 37 | call puts@PLT 38 | pxor %xmm3, %xmm3 39 | cvtss2sd -4(%rbp), %xmm3 40 | movq %xmm3, %rax 41 | movq %rax, %xmm0 42 | leaq .LC4(%rip), %rax 43 | movq %rax, %rsi 44 | leaq .LC5(%rip), %rax 45 | movq %rax, %rdi 46 | movl $1, %eax 47 | call printf@PLT 48 | movl $0, %eax 49 | leave 50 | .cfi_def_cfa 7, 8 51 | ret 52 | .cfi_endproc 53 | .LFE0: 54 | .size main, .-main 55 | .section .rodata 56 | .align 4 57 | .LC0: 58 | .long 1084227584 59 | .align 8 60 | .LC1: 61 | .long 0 62 | .long 1073741824 63 | .align 8 64 | .LC2: 65 | .long 776530087 66 | .long 1074340351 67 | .ident "GCC: (GNU) 11.1.0" 68 | .section .note.GNU-stack,"",@progbits 69 | -------------------------------------------------------------------------------- /introduction/area2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/introduction/area2 -------------------------------------------------------------------------------- /introduction/areaV1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/introduction/areaV1 -------------------------------------------------------------------------------- /introduction/entero.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //Declaracion de variable 4 | int progra; 5 | 6 | //Declaracion y asignacion de variable 7 | int pepe = 1000; 8 | 9 | int main(){ 10 | progra = 64; //Asignacion 11 | /*printf("La variable progra vale: %i\n", progra); 12 | printf("\tPepe, vales %i", pepe); 13 | 14 | pepe = 0; //Asignando nuevo valor a la variable 15 | printf("\tPepe, ahora vales %i", pepe); 16 | */ 17 | printf("\v"); 18 | printf("La variable progra vale: %i y %c", progra, progra); 19 | printf("\n"); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /introduction/hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/introduction/hello -------------------------------------------------------------------------------- /introduction/hello.c: -------------------------------------------------------------------------------- 1 | #include // stdio -> Standard Input/Output 2 | #define variable 32 3 | /*Variables*/ 4 | 5 | int numero; //Declaración de variable 6 | 7 | //retorno indetificador(argumentos){ } 8 | int main(void){ 9 | const int caracter = 64; 10 | printf("\n\nMi \"caracter\" es: %d\n\n", caracter); 11 | 12 | //caracter = 120; 13 | printf("\n\nMi \"caracter2\" es: %d\n\n", variable); 14 | 15 | return 0; 16 | } 17 | /*Funciones*/ 18 | -------------------------------------------------------------------------------- /introduction/hello.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/introduction/hello.o -------------------------------------------------------------------------------- /introduction/locale.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | setlocale(LC_CTYPE,"Spanish"); 5 | printf("Niños"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /introduction/locale_ASCII.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | printf("ni%cos \n",164);//ñ 7 | printf("ni%cos",165);//Ñ 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /introduction/midir/miarchivo.txt: -------------------------------------------------------------------------------- 1 | dasdasdas 2 | -------------------------------------------------------------------------------- /memory/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/memory/a.out -------------------------------------------------------------------------------- /memory/calloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /*Declaración e implementación de función*/ 5 | int Cantidad(){ 6 | int valor; 7 | printf("Números que deseas guardar: "); 8 | scanf("%i", &valor); //valor = 5 9 | return valor; // return 5; 10 | } 11 | 12 | void leerNumeros(int cantidad, char *numeros) { // 2, float *numeros 13 | for (int i =0;i < cantidad; i++) { // 2 < 2 14 | getchar(); 15 | printf("\nNúmero %d:",i + 1); // Número 1 + 1 = 2 --> Número 2 16 | scanf("%c",&numeros[i]); // &numeros[1] = 5 17 | } 18 | } 19 | 20 | void imprimirNumeros(int cantidad, char *numeros) { //2, float * numeros 21 | for (int i=0;i < cantidad; i++) { //2 < 2 22 | //printf("\nNúmero %d : %0.2f ", i+1, numeros[i]); 23 | printf("\nNúmero %d : %c \tDirección Memoria: %p", i+1, numeros[i], &numeros[i]); 24 | 25 | // Número 1 : 10 ", 0+1, numeros[0] 26 | // Número 2 : 5 ", 1+1, numeros[1] 27 | } 28 | } 29 | 30 | int main(void) { 31 | //Declaración y asignación de variable 32 | int cantidad = Cantidad(); // int cantidad = 2; 33 | 34 | /*(cast-type*)*/ 35 | /* calloc(n, element-size); */ 36 | /* calloc(5, 4) = 20 bytes */ 37 | 38 | char *numeros = (char*) calloc(cantidad, sizeof(char)); // 39 | //int *numeros = (int*) malloc(cantidad * sizeof(int)); // Malloc 40 | 41 | //imprimirNumeros(cantidad, numeros); // imprimirNumeros(5, numeros[]) 42 | 43 | /*inicializa a 0 la memoria reservada*/ 44 | leerNumeros(cantidad, numeros); // leerNumero(5, numeros[]); 45 | imprimirNumeros(cantidad, numeros); // imprimirNumero(5, numeros[]); 46 | 47 | free(numeros); //Liberar la memoria 48 | printf("\n\n\tMemoria Liberada\n------------------------------"); 49 | imprimirNumeros(cantidad, numeros); // imprimirNumeros(5, numeros[]) 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /memory/calloc2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n, i, *ptr, sum = 0; 7 | 8 | printf("Número de elementos: "); 9 | scanf("%d", &n); 10 | 11 | ptr = (int*) calloc(n, sizeof(int)); 12 | if(ptr == NULL) 13 | { 14 | printf("¡Error al reservar memoria! ."); 15 | exit(0); 16 | } 17 | 18 | printf("Ingresa los elementos a sumar:\n"); 19 | for(i = 0; i < n; ++i) 20 | { 21 | scanf("%d", ptr + i); 22 | sum += *(ptr + i); 23 | } 24 | 25 | printf("La suma = %d", sum); 26 | free(ptr); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /memory/malloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /*Funciones*/ 5 | 6 | int Cantidad() { 7 | int cantidad; 8 | printf("\nNúmeros que deseas guardar: "); 9 | scanf("%i", &cantidad); //3 cantidad = 3 10 | return cantidad; // return 3 11 | } 12 | 13 | void leerNumeros(int cantidad, int *numeros) { // 3, 14 | for (int i =0;i < cantidad; i++) { 15 | printf("\nNúmero %d:",i + 1); // 5, 10, 3 16 | scanf("%i",&numeros[i]); //numeros[0] = 5 numeros[1] = 10 numeros[2] = 3 17 | } 18 | } 19 | 20 | void imprimirNumeros(int cantidad, int *numeros) { 21 | for (int i=0;i < cantidad; i++) { 22 | printf("\nNúmero %d : %i \tDirección Memoria: %p", i+1, numeros[i], &numeros[i]); 23 | } 24 | } 25 | 26 | 27 | int main(void) { 28 | //Declaración de variable*/ 29 | int cantidad = Cantidad(); //int cantidad = 3; 30 | /*(cast-type*) malloc(byte-size)*/ 31 | /* Manejo Dinámico de Memoria */ 32 | // malloc(30 * 4 bytes) 33 | 34 | int *numeros = (int*) malloc(cantidad * sizeof(int)); //Aparto el espacio en memoria de forma dinámica 35 | //(int*) malloc(3 * 4 bytes); 36 | 37 | //imprimirNumeros(cantidad, numeros); /*Mostrando los valores*/ 38 | // 3, numeros 39 | 40 | 41 | leerNumeros(cantidad, numeros); /*Asignando valor a los espacios de memoria */ 42 | imprimirNumeros(cantidad, numeros); /*Mostrando los valores*/ 43 | 44 | free(numeros); //Liberar la memoria 45 | 46 | printf("\n\n\tMemoria Liberada\n------------------------------"); 47 | imprimirNumeros(cantidad, numeros); // imprimirNumeros(5, numeros[]) 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /memory/malloc2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n, i, *ptr, sum = 0; 7 | 8 | printf("Número de elementos: "); 9 | scanf("%d", &n); 10 | 11 | ptr = (int*) malloc(n * sizeof(int)); 12 | 13 | if(ptr == NULL){ 14 | printf("¡Error al reservar memoria! ."); 15 | exit(0); 16 | } 17 | 18 | printf("Ingresa los elementos a sumar:\n"); 19 | for(i = 0; i < n; ++i){ 20 | scanf("%d", ptr + i); 21 | sum += *(ptr + i); //sum = 0 + *(ptr + i) 30 = 30 ---> sum = 30 + 2 = 32 22 | //sum += sum; 23 | } 24 | 25 | printf("La suma = %d", sum); 26 | free(ptr); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /memory/realloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int i, x; 5 | 6 | /*Declaración e implementación de función*/ 7 | int Cantidad(){ 8 | int valor; 9 | printf("Números que deseas guardar: "); 10 | scanf("%i", &valor); //valor = 5 11 | return valor; // return 5; 12 | } 13 | 14 | int leerNumeros(int inicio, int cantidad, int *numeros) { // 0, 2, int *numeros 15 | printf("Imprimiendo números\n"); 16 | for (i = inicio; i < cantidad; i++) { // 2 < 2 17 | printf("\nNúmero %d:",i + 1); // Número (1 + 1) --> Numero 2: 18 | scanf("%d",&numeros[i]); // &numeros[0] = 2, &numeros[1] = 10 19 | } 20 | printf("El valor de i es %d", i); 21 | return i; //2 //Regresando posición de arreglo 22 | } 23 | 24 | void imprimirNumeros(int inicio, int cantidad, int *numeros) { //2, float * numeros 25 | for (i = inicio; i < cantidad; i++) { //2 < 2 26 | printf("\nNúmero %d : %d\tMemoria: %p", i+1, numeros[i], &numeros[i]); 27 | // Número 1 : 10 ", 0+1, numeros[0] 28 | // Número 2 : 5 ", 1+1, numeros[1] 29 | } 30 | } 31 | 32 | int main(){ 33 | 34 | int *ptr; //Declarado variables 35 | int inicio = 0; 36 | int n = Cantidad(); // n1 = 2 37 | 38 | ptr = (int*) malloc(n * sizeof(int)); //Alojando memoria 39 | //int *ptr = (int*) malloc(n * sizeof(int)); 40 | // malloc(2 * 4) --> 8 bytes; 41 | 42 | printf("Dirección de memoria reservada:\n"); 43 | for(int i = 0; i < n; ++i){ 44 | printf("%u\t%p\n", *ptr +i, &ptr + i); //Imprimiendo direcciones de memoria 45 | } 46 | x = leerNumeros(inicio, n, ptr); //Almacena los valores arreglo y guarda en x = 2 47 | imprimirNumeros(inicio, n, ptr); 48 | 49 | printf("\nIngresa nuevo tamaño de arreglo\n"); 50 | n = Cantidad(); // n1 = 51 | 52 | //realloc(arreglo, nuevaCantidad * tipoDato) 53 | ptr = realloc(ptr, n * sizeof(int)); 54 | //realloc(ptr, 5 * 4) ---> realloc(ptr, 20 bytes) 55 | 56 | printf("Nueva Dirección de memoria reservada: \n"); 57 | for(int i = 0; i < n; ++i){ 58 | printf("%i\t%p\n", i + 1, &ptr[i]); //Imprimiendo direcciones de memoria 59 | } 60 | leerNumeros(x, n, ptr); 61 | imprimirNumeros(inicio, n, ptr); 62 | free(ptr); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /pointer/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/pointer/a.out -------------------------------------------------------------------------------- /pointer/apuntador.c: -------------------------------------------------------------------------------- 1 | /*Operador de dirección: & 2 | Para poder obtener la dirección de una variable 3 | Para poder almacenar la direccion hará falta una variable puntero con el mismo tipo 4 | sintáxis) 5 | */ 6 | 7 | /* 8 | Operador de indirección: * 9 | Para de acceder al dato almacenado en una dirección 10 | Realiza la función opuesta del operador & 11 | 12 | 13 | Tipo_dato *nombre de apuntador; 14 | */ 15 | #include 16 | 17 | //Declaración variables 18 | int num1, num2; //Entero 19 | int *apuntador = &num1; // Apuntador de tipo entero 20 | //tipo_dato *identificado; 21 | 22 | char valor; 23 | char *apuntadorChar; //Declarando apuntadores 24 | //TipoDato *nombreIdentificador; 25 | 26 | int main (){ 27 | //Variables 28 | num1 = 1000; 29 | num2 = 500; 30 | valor = '@'; 31 | //num2 = 5; //Asignando un valor 32 | //Apuntador (variable) 33 | //scanf("%i", &num1); 34 | 35 | //apuntador = &num1; 36 | apuntadorChar = &valor; 37 | 38 | puts("Apuntando a un entero:"); 39 | printf("\tNum1 tiene el valor: %d y esta alojado en: %p\n", num1, &num1); 40 | //printf("\n\tNum2 tiene el valor: %d y esta alojado en: %p\n", num2, &num2); 41 | printf("\tEl apuntador tiene el valor: %p y esta alojado en: %p\n", apuntador, &apuntador); 42 | printf("\tEl valor del entero al que apunta pointer es: %d\n\n", *apuntador); 43 | 44 | puts("Apuntando a un caracter:"); 45 | printf("\tMi char tiene el valor: %c y esta alojado en: %p\n", valor, &valor); 46 | printf("\tEl apuntador tiene el valor: %p y esta alojado en: %p\n", apuntadorChar, &apuntadorChar); 47 | printf("\tEl valor del entero al que apunta pointer es: %c\n", *apuntadorChar); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /pointer/apuntador_arreglo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/pointer/apuntador_arreglo -------------------------------------------------------------------------------- /pointer/apuntador_arreglo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //mi_arreglo[0]=1; 4 | //mi_arreglo[1]=230; 5 | //mi_arreglo[2]=17; 6 | //mi_arreglo[3]=14; 7 | //mi_arreglo[4]=-5; 8 | //mi_arreglo[5]=1000; 9 | //mi_arreglo[6]=21; 10 | //int mi_arreglo[] = {1,230,17,14,-5,1000, 21}; //entero 11 | char mi_arreglo2[6] = {'A','B','C','D'}; //char 12 | //int *ptr; 13 | char *ptr2; 14 | //int i; 15 | 16 | int main(void){ 17 | // ptr = &mi_arreglo[0]; /* apuntamos nuestro puntero*/ 18 | ptr2 = &mi_arreglo2[0]; /* apuntamos nuestro puntero*/ 19 | 20 | printf("\n\n"); 21 | 22 | // for (int i = 0; i < 10; i++){ //0-6 23 | // printf("mi_arreglo[%d] = %d ", i, mi_arreglo[i]); 24 | /* printf("ptr + %d = %d\n",i, *(ptr + i));*/ 25 | //printf ("\n\tptr + %d = %d\n", i, *ptr++); 26 | // printf("\tptr apunta a: %p\n", &ptr + i); 27 | // } 28 | 29 | for (int i = 0; i < 5; i++){ 30 | printf("Valor del arreglo: mi_arreglo2[%d] = %c ", i, mi_arreglo2[i]); 31 | printf("\n\tValor de arreglo2 ocupando apuntador: ptr2 + %d = %c",i, *(ptr2 + i)); 32 | // &ptr2 = 0x55c28a4cd048 33 | // *ptr2 = A 34 | printf("\n\tDirección de memoria almacenada en apuntador:ptr2 apunta a: %p\n\n", &ptr2 + i); 35 | // A B C D 36 | // A --> &ptr2 + 0 = 0x55c28a4cd048 37 | // B --> &ptr2 + 1 = 0x55c28a4cd050 38 | // C --> &ptr2 + 2 = 0x55c28a4cd058 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /pointer/apuntador_arreglo2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/pointer/apuntador_arreglo2 -------------------------------------------------------------------------------- /pointer/apuntador_arreglo2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char strA[80] = "Cadena 1"; 4 | char strB[80]; 5 | int i; 6 | char *pA; /* un apuntador al tipo caracter */ 7 | char *pB; /* otro apuntador al tipo caracter */ 8 | 9 | int main(void) 10 | { 11 | /* puts(strA); muestra la cadena strA */ 12 | pA = strA; /* apunta pA a la cadena strA */ 13 | /* puts(pA); muestra a donde apunta pA */ 14 | pB = strB; /* apunta pB a la cadena strB */ 15 | putchar('\n'); /* dejamos una línea en blanco */ 16 | i = 0; 17 | while(*pA != '\0') /* linea A (ver texto) */ 18 | { 19 | *pB++ = *pA++; /* linea B (ver texto) */ 20 | printf("pB apunta a: %p\n", &pB + i); 21 | puts(strB); /* muestra strB en la pantalla */ 22 | i++; 23 | } 24 | *pB = '\0'; /* linea C (ver texto) */ 25 | puts(strB); /* muestra strB en la pantalla */ 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /pointer/apuntador_struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct datos{ 4 | char nombre[20]; /* nombre */ 5 | char apellido[20]; /* apellido */ 6 | int edad; /* edad */ 7 | float salario; /* salario */ 8 | }; 9 | struct datos mis_datos; /* definimos mis_datos del tipo |:%estructura datos */ 10 | void show_name (struct datos *p); /* prototipo de la función */ 11 | 12 | int main(void) 13 | { 14 | struct datos *st_ptr; /* un apuntador a una estructura del tipo datos */ 15 | st_ptr = &mis_datos; /* apuntamos el apuntador a mis_datos */ 16 | strcpy(mis_datos.apellido,"Jensen"); 17 | strcpy(mis_datos.nombre,"Ted"); 18 | printf("\n%s ",mis_datos.nombre); 19 | printf("%s\n",mis_datos.apellido); 20 | mis_datos.edad = 63; 21 | show_name (st_ptr); /* Llamamos a la función pasándole el puntero */ 22 | return 0; 23 | } 24 | 25 | void show_name(struct tag *p) 26 | { 27 | printf("\n%s ", p --> nombre); /* p apunta a una estructura */ 28 | printf("%s ", p --> apellido); 29 | printf("%d\n", p --> edad); 30 | } 31 | -------------------------------------------------------------------------------- /pointer/for5_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/pointer/for5_1 -------------------------------------------------------------------------------- /pointer/for5_1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(void) 4 | { 5 | int x,y,z; 6 | int *pointer; 7 | x=0; 8 | y=1; 9 | pointer = &z; 10 | for (int cont=0;cont<3;cont++){ 11 | z=x+y; //z = 2 + 3; 12 | printf("%d\n",z); //5 13 | printf("pointer tiene el valor: %d y esta alojado en: %p\n", z, &z); 14 | printf("pointer tiene el valor: %p y esta alojado en: %p\n", pointer, &pointer); 15 | printf("El valor del entero al que apunta pointer es: %d\n", *pointer); 16 | x=y; //x = 2 17 | y=z; //y = 5 18 | } 19 | getchar(); 20 | return 0; 21 | } 22 | /*Podemos “desreferenciar” un apuntador, es decir, hacer referencia al valor contenido en la dirección a la que apunta, usando el operador unitario ‘*’, como en *pointer*/ 23 | -------------------------------------------------------------------------------- /struct/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/struct/a.out -------------------------------------------------------------------------------- /struct/data.h: -------------------------------------------------------------------------------- 1 | struct biblioteca { // Crea la estructura del registro 2 | int code; 3 | char titulo[20]; 4 | char autor[20]; 5 | }libro; 6 | -------------------------------------------------------------------------------- /struct/data3.h: -------------------------------------------------------------------------------- 1 | struct biblioteca { // Crea la estructura del registro 2 | char codigo[10]; 3 | char titulo[50]; 4 | char autor[50]; 5 | }libro2; -------------------------------------------------------------------------------- /struct/enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct datos{ 5 | char constelacion[60]; 6 | char nombre[20]; 7 | }caballero[13]; 8 | 9 | enum Zodiaco 10 | { 11 | Aries, 12 | Tauro, 13 | Geminis, 14 | Cancer, 15 | Leo, 16 | Virgo, 17 | Libra, 18 | Escorpio, 19 | Ofiuco, 20 | Sagitario, 21 | Capricornio, 22 | Acuario, 23 | Piscis 24 | }casa; 25 | 26 | int main() 27 | { 28 | strcpy(caballero[Aries].constelacion, "Aries"); 29 | strcpy(caballero[Aries].nombre, "Shion"); 30 | strcpy(caballero[Tauro].constelacion, "Tauro"); 31 | strcpy(caballero[Tauro].nombre, "Ox"); 32 | strcpy(caballero[Geminis].constelacion, "Geminis"); 33 | strcpy(caballero[Geminis].nombre, "Cain/Abel"); 34 | strcpy(caballero[Cancer].constelacion, "Cancer"); 35 | strcpy(caballero[Cancer].nombre, "Deathtoll"); 36 | strcpy(caballero[Leo].constelacion, "Leo"); 37 | strcpy(caballero[Leo].nombre, "Kaiser"); 38 | strcpy(caballero[Virgo].constelacion, "Virgo"); 39 | strcpy(caballero[Virgo].nombre, "Shijima"); 40 | strcpy(caballero[Libra].constelacion, "Libra"); 41 | strcpy(caballero[Libra].nombre, "Dohko"); 42 | strcpy(caballero[Escorpio].nombre, "Escorpio"); 43 | strcpy(caballero[Escorpio].constelacion, "Ecarlate"); 44 | strcpy(caballero[Ofiuco].constelacion, "Ofiuco"); 45 | strcpy(caballero[Ofiuco].nombre, "Odysseus"); 46 | strcpy(caballero[Sagitario].constelacion, "Sagitario"); 47 | strcpy(caballero[Sagitario].nombre, "Gestalt"); 48 | strcpy(caballero[Capricornio].constelacion, "Capricornio"); 49 | strcpy(caballero[Capricornio].nombre, "Izo"); 50 | strcpy(caballero[Acuario].constelacion, "Acuario"); 51 | strcpy(caballero[Acuario].nombre, "Mistria"); 52 | strcpy(caballero[Piscis].constelacion, "Piscis"); 53 | strcpy(caballero[Piscis].nombre, "Cardinale"); 54 | 55 | for (casa = Aries; casa <= Piscis; casa++) 56 | { 57 | printf("\nEl caballero %s de %s resguarda la casa %d del santuario", caballero[casa].nombre, caballero[casa].constelacion, casa+1); 58 | } 59 | puts("\n"); 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /struct/enum2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | enum Semana 5 | { 6 | domingo=1, 7 | lunes, 8 | martes, 9 | miercoles, 10 | jueves, 11 | viernes, 12 | sabado 13 | }dia; 14 | 15 | int main() 16 | { 17 | for (dia = domingo; dia <= sabado; dia++) //for(casa=0; casa<=13; casa++) 18 | { 19 | printf("\nHoy es el dia %d de la semana", dia); 20 | } 21 | puts("\n"); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /struct/struct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/struct/struct -------------------------------------------------------------------------------- /struct/struct.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | 4 | /* 5 | struct persona { 6 | int edad; 7 | char nombre[20]; 8 | direccion 9 | ... 10 | ... 11 | } 12 | 13 | struct persona alumno = {0}; 14 | struct persona profesor = {0}; 15 | 16 | */ 17 | struct biblioteca { // Crea la estructura del registro 18 | int codigo; 19 | char titulo[20]; 20 | char autor[20]; 21 | }libro, revista; 22 | 23 | //libro, libro2, libro3; 24 | 25 | //struct biblioteca libro = {0}; // Define libro con el tipo de dato elibro 26 | 27 | int main(){ // Inicio 28 | // system("clear"); // Limpia pantalla 29 | // Ingresa datos del registro 30 | printf("\nIngrese Libro:\n"); 31 | printf("Ingrese el codigo:"); 32 | scanf("%d",&libro.codigo); 33 | printf("Ingrese el título del libro:"); 34 | scanf("%s", libro.titulo); 35 | printf("Ingrese el nombre del autor:"); 36 | scanf("%s",libro.autor); 37 | // Imprime el registro 38 | printf("Registro: %d : %s %s\n", libro.codigo, libro.titulo, libro.); 39 | 40 | printf("\nIngrese Revista:\n"); 41 | printf("Ingrese el codigo:"); 42 | scanf("%d",&revista.codigo); 43 | printf("Ingrese el título del revista:"); 44 | scanf("%s", revista.titulo); 45 | printf("Ingrese el nombre del autor:"); 46 | scanf("%s",revista.autor); 47 | // Imprime el registro 48 | printf("Registro: %d : %s %s\n", revista.codigo, revista.titulo, revista.autor); 49 | return 0; 50 | } // Fin de programa| -------------------------------------------------------------------------------- /struct/struct2.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | #include "data.h" // Archivo de cabecera para subrutinas de utilidades 4 | 5 | int main(){ 6 | printf("Ingrese el codigo:"); 7 | scanf("%d",&libro.code); 8 | printf("Ingrese el título del libro:"); 9 | scanf("%s",libro.titulo); 10 | printf("Ingrese el nombre del autor:"); 11 | scanf("%s",libro.autor); 12 | printf("Registro: %d %s %s\n",libro.code,libro.titulo,libro.autor); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /struct/struct3.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | #include "data3.h" 4 | 5 | int main() 6 | { // Inicio 7 | system("clear"); // Limpia pantalla 8 | //struct biblioteca libro2; 9 | // Ingresa datos del registro 10 | fflush(stdin); 11 | printf("Ingrese el codigo:"); 12 | fgets(libro2.codigo, 10 , stdin); 13 | fflush(stdin); 14 | printf("Ingrese el nombre del autor:"); 15 | fgets(libro2.autor, 50, stdin); 16 | fflush(stdin); 17 | printf("Ingrese el título del libro:"); 18 | /*scanf("%s",libro.titulo);*/ 19 | fgets(libro2.titulo, 50, stdin); 20 | // scanf("%s",libro.autor); 21 | // Imprime el registro 22 | printf("Registro: %s %s %s\n",libro2.codigo,libro2.titulo,libro2.autor); 23 | return 0; 24 | } // Fin de programa| 25 | -------------------------------------------------------------------------------- /struct/struct3_1.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | #include 4 | 5 | struct biblioteca { // Crea la estructura del registro 6 | char codigo[10]; 7 | char titulo[50]; 8 | char autor[50]; 9 | }libro2; 10 | 11 | void limpiar (char *cadena) 12 | { 13 | char *p; 14 | p = strchr (cadena, '\n'); 15 | if (p) 16 | *p = '\0'; 17 | } 18 | 19 | int main() 20 | { // Inicio 21 | system("clear"); // Limpia pantalla 22 | // Ingresa datos del registro 23 | fflush(stdin); 24 | printf("Ingrese el codigo:"); 25 | fgets(libro2.codigo, 10 , stdin); 26 | fflush(stdin); 27 | printf("Ingrese el nombre del autor:"); 28 | fgets(libro2.autor, 50, stdin); 29 | limpiar(libro2.autor); 30 | fflush(stdin); 31 | printf("Ingrese el título del libro:"); 32 | fgets(libro2.titulo, 50, stdin); 33 | limpiar(libro2.titulo); 34 | // Imprime el registro 35 | printf("Registro: %d %s %s\n",atoi(libro2.codigo),libro2.titulo,libro2.autor); 36 | return 0; 37 | } // Fin de programa| 38 | 39 | -------------------------------------------------------------------------------- /struct/struct4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | struct datos{ 7 | char nombre[60]; 8 | int edad; 9 | char ciudad[20]; 10 | }persona[20]; // Array de struct con datos para 3 personas. 11 | 12 | int reg = 0; 13 | 14 | puts("¿Cuántos registros deseas?:"); //puts funciona igual que printf 15 | scanf("%d", ®); 16 | getchar(); //Pausa 17 | 18 | int i, numero=0; 19 | for (i=0; i 2 | #include 3 | 4 | struct info{ 5 | char nombre[25]; 6 | char apPaterno[25]; 7 | char apMaterno[25]; 8 | char direccion[25]; 9 | }; 10 | 11 | struct academico{ 12 | char numeroEmpleado[13]; 13 | struct info datos_profesor; 14 | }profesor; 15 | 16 | struct alumnado{ 17 | char numeroCuenta[13]; 18 | char promedio[5]; 19 | struct info datos_estudiante; // 20 | }estudiante; 21 | 22 | int main(void){ 23 | // strcopy(CadenaDondeSeCopia , CadenaACopiar ); 24 | strcpy(profesor.datos_profesor.nombre,"Daniel"); //strcpy 25 | strcpy(profesor.datos_profesor.nombre,"J"); //strcpy 26 | strcpy(profesor.datos_profesor.apPaterno,"Rosales"); 27 | strcpy(profesor.datos_profesor.apMaterno,"Mendoza"); 28 | strcpy(profesor.datos_profesor.direccion, "Valhalla"); 29 | strcpy(profesor.numeroEmpleado, "123456789"); 30 | 31 | /* imprimimos los datos */ 32 | printf("\n Planta Docente: "); 33 | printf("\n Nombre: %s %s %s", profesor.datos_profesor.nombre, profesor.datos_profesor.apPaterno, profesor.datos_profesor.apMaterno); 34 | printf("\n RFC: %s", profesor.numeroEmpleado); 35 | printf("\n Direccion: %s", profesor.datos_profesor.direccion); 36 | 37 | strcpy(estudiante.datos_estudiante.nombre,"Juan"); 38 | strcpy(estudiante.datos_estudiante.apPaterno,"Rojas"); 39 | strcpy(estudiante.datos_estudiante.apMaterno,"Méndez"); 40 | strcpy(estudiante.datos_estudiante.direccion,"Midgard"); 41 | strcpy(estudiante.numeroCuenta, "315093450"); 42 | strcpy(estudiante.promedio, "9.98"); 43 | 44 | /* imprimimos los datos */ 45 | printf("\n"); 46 | printf("\n Alumnado: "); 47 | printf("\n Nombre: %s %s %s", estudiante.datos_estudiante.nombre, estudiante.datos_estudiante.apPaterno, estudiante.datos_estudiante.apMaterno ); 48 | printf("\n NumCuenta: %s", estudiante.numeroCuenta); 49 | printf("\n Promedio: %s", estudiante.promedio); 50 | printf("\n Direccion: %s", estudiante.datos_estudiante.direccion); 51 | printf("\n"); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /struct/struct_anidadoV2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct direccion{ 6 | char calle[25]; 7 | int numInt; 8 | int numExt; 9 | char colonia[25]; 10 | char cp[5]; 11 | }; 12 | struct info{ 13 | char nombre[25]; 14 | char apPaterno[25]; 15 | char apMaterno[25]; 16 | struct direccion dir; 17 | }; 18 | struct academico{ 19 | char numeroEmpleado[13]; 20 | struct info datos_profesor; 21 | }profesor; 22 | 23 | struct alumnado{ 24 | char numeroCuenta[13]; 25 | char promedio[5]; 26 | struct info datos_estudiante; // 27 | }estudiante; 28 | 29 | int main(void){ 30 | int op; 31 | 32 | puts("¿Qué deseas capturar?"); 33 | puts("1.-Profesorado"); 34 | puts("2.-Alumnado"); 35 | 36 | scanf("%i", &op); 37 | 38 | char *apuntador[13]; 39 | 40 | *apuntador = profesor.numeroEmpleado; 41 | 42 | if(op == 1){ 43 | getchar(); 44 | printf("Dame número empleado: "); 45 | //fgets(profesor.numeroEmpleado,13,stdin); 46 | fgets(*apuntador,13,stdin); 47 | 48 | printf("Dame nombre: "); 49 | //strcpy(profesor.datos_profesor.nombre, "Daniel\n"); 50 | fgets(profesor.datos_profesor.nombre, 25, stdin); 51 | printf("Dame apellido paterno: "); 52 | fgets(profesor.datos_profesor.apPaterno, 25, stdin); 53 | printf("Dame apellido materno: "); 54 | fgets(profesor.datos_profesor.apMaterno, 25, stdin); 55 | printf("Dame la calle donde vives: "); 56 | fgets(profesor.datos_profesor.dir.calle,25 ,stdin ); 57 | printf("Dame el número interior: "); 58 | scanf("%d", &profesor.datos_profesor.dir.numInt); 59 | //printf("\n\tID: %s \n\tNombre:%s %s %s\n Dirección: %s %d", *apuntador , profesor.datos_profesor.nombre, profesor.datos_profesor.apPaterno, profesor.datos_profesor.apMaterno, profesor.datos_profesor.dir.calle, profesor.datos_profesor.dir.numInt); 60 | printf("%s", *apuntador); 61 | }else if(op == 2){ 62 | getchar(); 63 | printf("Dame número empleado: "); 64 | fflush(stdin); 65 | fgets(estudiante.numeroCuenta,13,stdin); 66 | printf("Dame nombre: "); 67 | fflush(stdin); 68 | fgets(estudiante.datos_estudiante.nombre, 25, stdin); 69 | printf("Dame apellido paterno: "); 70 | fflush(stdin); 71 | fgets(estudiante.datos_estudiante.apPaterno, 25, stdin); 72 | printf("Dame apellido materno: "); 73 | fflush(stdin); 74 | fgets(estudiante.datos_estudiante.apMaterno, 25, stdin); 75 | printf("\n\tID: %s \n\tNombre:%s %s %s", estudiante.numeroCuenta, estudiante.datos_estudiante.nombre, estudiante.datos_estudiante.apPaterno, estudiante.datos_estudiante.apMaterno); 76 | 77 | }else{ 78 | printf("Dame una opción válida"); 79 | } 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /struct/struct_union.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /*Creamos una union*/ 5 | union mensajesUnion{ 6 | char bienvenida[25]; 7 | char nombre[25]; 8 | } saludoUnion; 9 | 10 | /*Creamos una estructura*/ 11 | struct mensajesStruct{ 12 | char bienvenida[25]; 13 | char nombre[25]; 14 | }saludoStruct; 15 | 16 | 17 | int main(){ 18 | 19 | /*/////////////////UNION////////////////////////*/ 20 | /* Las uniones usan el mismo espacio de memoria para todos los elementos 21 | * de la union, toma el tamaño del elemento de mayor tamaño, en este caso 25 bytes. 22 | * Los elementos dentro de la union comparten esos 25 bytes. 23 | */ 24 | /*Copiamos cadenas*/ 25 | strcpy(saludoUnion.bienvenida, "Hola"); 26 | strcpy(saludoUnion.nombre, "Juan"); 27 | 28 | //scanf("%s", saludoUnion.bienvenida); 29 | 30 | //scanf("%s", saludoUnion.nombre); 31 | //saludoUnion.nombre[20]="Ho"; 32 | //fgets(saludoUnion.bienvenida, 25, stdin); 33 | //fgets(saludoUnion.nombre, 25, stdin); 34 | 35 | 36 | printf("\nUnion: "); 37 | 38 | /*Imprimimos mensajes de union*/ 39 | printf("\n1.- %s", saludoUnion.bienvenida); 40 | printf("\n2.- %s", saludoUnion.nombre); 41 | 42 | /*/////////////////STRUCT////////////////////////*/ 43 | /* En la estructura se reservan 75 bytes de memoria en total, 44 | * en este caso cada uno es independiente en memoria, 45 | * se puede inicializar cada uno o usar como un campo independiente. 46 | */ 47 | 48 | /*Copiamos cadenas*/ 49 | strcpy(saludoStruct.bienvenida, "Hi"); 50 | strcpy(saludoStruct.nombre, "Jhon\n"); 51 | 52 | printf("\nStruct: \n"); 53 | 54 | /*Imprimimos mensajes de union*/ 55 | printf("\n1.- %s", saludoStruct.bienvenida); 56 | printf("\n2.- %s", saludoStruct.nombre); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /struct/structv2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include // 3 | 4 | int main() 5 | { 6 | struct datos{ 7 | char nombre[60]; 8 | int edad; 9 | char ciudad[20]; 10 | }persona[20]; // Array de struct con datos para 3 personas. 11 | 12 | int reg; 13 | 14 | puts("¿Cuántos registros deseas?:"); 15 | 16 | scanf("%d", ®); 17 | //printf("%d", reg); 18 | 19 | int i, numero=0; 20 | for (i=0; i 2 | #include 3 | 4 | int main() 5 | { 6 | union datos{ // 7 | char nombre[60]; 8 | int edad; 9 | char ciudad[20]; 10 | }persona[20]; // Array de struct con datos para 3 personas. 11 | 12 | int reg; 13 | 14 | puts("¿Cuántos registros deseas?:"); 15 | scanf("%d", ®); 16 | getchar(); 17 | 18 | int i, numero=0; 19 | for (i=0; i 2 | 3 | union dato { 4 | int x; 5 | char letra; 6 | float z; 7 | }d; 8 | 9 | int main() 10 | { 11 | union dato d; 12 | d.x=10; 13 | printf("Impresion del entero:%i\n",d.x); 14 | d.letra='A'; 15 | printf("Impresion del caracter:%c\n",d.letra); 16 | printf("Impresion del entero:%i\n",d.x); //El dato se ha modificado 17 | d.z=5.25; 18 | printf("Impresion del float:%0.2f\n",d.z); 19 | printf("Impresion del entero:%i\n",d.x); //El dato se ha modificado nuevamente 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /variables/1_variables/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/1_variables/a.out -------------------------------------------------------------------------------- /variables/1_variables/tipoDatoformatos.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | // Caracteres 5 | char c = 'A'; 6 | printf("Caracter: %c \n", c); 7 | printf("Caracter en decimal: %d \n", c); 8 | printf("Caracter en decimal: %i \n", c); 9 | printf("Caracter en octal: %o \n", c); 10 | printf("Caracter en hexadecimal: %x\n", c); 11 | 12 | //Números enteros 13 | short ec= 10; 14 | printf("Entero corto: %i \n", ec); 15 | printf("Entero corto: %d \n", ec); 16 | printf("Entero corto en octal: %o \n", ec); 17 | printf("Entero corto en hexadecimal: %x \n", ec); 18 | 19 | int ec2= -10000; 20 | printf("Numero entero corto: %i \n", ec2); 21 | 22 | //Números enteros largos 23 | signed long el= 9999999; 24 | printf("Entero largo: %ld \n", el); 25 | printf("Entero largo: %li \n", el); 26 | 27 | //Números reales cortos 28 | float rc= 25.244696; 29 | printf("Numero reales cortos: %f \n", rc); 30 | printf("Numero reales cortos: %e \n", rc); //formato científico 31 | printf("Numero reales cortos: %g \n", rc); // redondeo 32 | 33 | //Numeros reales largos 34 | double rl= 22.1635423423455423233553; 35 | printf("Numero reales largo: %lf \n", rl); 36 | printf("Numero reales largo: %.10lf \n", rl); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /variables/1_variables/variables: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/1_variables/variables -------------------------------------------------------------------------------- /variables/1_variables/variables.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void){ 4 | float var = 65; 5 | 6 | printf("\tPrimer printf: %f\n", var); 7 | printf("\tSegundo printf: %d\n", var); 8 | printf("\tTercer printf: %c\n", var); 9 | // fin 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /variables/1_variables/variables2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | float a,b,c,d, e; 6 | int a1, b1; 7 | int main() 8 | { 9 | system("clear"); 10 | printf("Dame el primer numero\n"); 11 | scanf("%f",&a); 12 | a1 = a; 13 | printf("Dame el segundo numero\n"); 14 | scanf("%f",&b); 15 | b1 = b; 16 | 17 | printf("Suma\n"); 18 | c=a+b; // Suma o adición 19 | printf("\t%f + %f = %f\n",a,b,c); 20 | printf("Resta\n"); 21 | c=a-b; // Resta o diferencia 22 | printf("\t%f - %f = %f\n",a,b,c); 23 | printf("Multiplicación\n"); 24 | c=a*b; // Multiplicación o producto 25 | printf("\t%f * %f = %f\n",a,b,c); 26 | printf("División\n"); 27 | c=a/b; // División o cociente tipo real 28 | printf("\t%f / %f = %f\n",a,b,c); 29 | printf("Módulo\n"); 30 | c=a1%b1; // Resto o módulo 31 | printf("\tEl módulo de %d/%d es %f\n",a1,b1,c); 32 | printf("Raíz cuadrada del primer numero\n"); 33 | c=sqrt(a); // Raíz cuadrada 34 | printf("\tLa Raíz cuadrada de %f es %f\n",a,c); 35 | printf("Raíz cuadrada del segundo numero\n"); 36 | c=sqrt(b); // Raíz cuadrada 37 | printf("\tLa Raíz cuadrada de %f es %f\n",b,c); 38 | printf("Potencia\n"); 39 | c = pow(b, a); //Potencia 40 | printf("\tEl número %f elevado a la potencia %f es %f\n",b,a,c); 41 | 42 | printf("Resultado del reto viral de Agosto\n"); 43 | 44 | c = a/(b*(b+b)); 45 | d = a/b*(b+b); 46 | printf("\tEl resultado de %f/(%f(%f+%f))es %f\n",a,b,b,b,c); 47 | printf("\tEl resultado de %f/%f(%f+%f)es %f\n",a,b,b,b,d); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /variables/1_variables/variables_constantes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/1_variables/variables_constantes -------------------------------------------------------------------------------- /variables/1_variables/variables_constantes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define num 10 3 | 4 | void main(void){ 5 | const int constante=32; //Declarando una constante 6 | int variable=12; //Declarando una variable 7 | 8 | printf("Valor de constante: %d\n", constante); 9 | printf("Valor de variable: %d\n", variable); 10 | printf("Valor de macro:%d\n", num); 11 | 12 | printf("\n\nCambiando valores...\n\n"); 13 | 14 | //constante=10; 15 | variable=0; 16 | //#define num 300 17 | 18 | printf("Nuevo valor de constante:%d\n", constante); 19 | printf("Nuevo valor de variable:%d\n", variable); 20 | printf("Nuevo valor de macro:%d\n", num); 21 | return; 22 | } 23 | -------------------------------------------------------------------------------- /variables/2_size/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/2_size/a.out -------------------------------------------------------------------------------- /variables/2_size/size_float: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/2_size/size_float -------------------------------------------------------------------------------- /variables/2_size/size_float.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | printf("Limites de tipos flotantes\n"); 8 | printf("*\n"); 9 | printf("Float\n"); 10 | printf("Mínimo: %f\n",FLT_MIN); 11 | printf("Máximo: %f\n",FLT_MAX); 12 | 13 | printf("*\n"); 14 | printf("Double\n"); 15 | printf("Mínimo: %lf\n",DBL_MIN); 16 | printf("Máximo: %lf\n",DBL_MAX); 17 | 18 | printf("*\n"); 19 | printf("Long Double\n"); 20 | printf("Mínimo: %LF\n",LDBL_MIN); 21 | printf("Máximo: %LF\n",LDBL_MAX); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /variables/2_size/size_int: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/2_size/size_int -------------------------------------------------------------------------------- /variables/2_size/size_int.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Limites de tipos enteros\n"); 7 | printf("*\n"); 8 | printf("CHAR BIT\n"); 9 | printf("Numero de bits en un byte : %d\n",CHAR_BIT); 10 | printf("Numero maximo de bytes en un carácter multibyte : %d\n",MB_LEN_MAX); 11 | printf("*\n"); 12 | printf("Caracter con signo\n"); 13 | printf("Mínimo: %d\n",CHAR_MIN); 14 | printf("Máximo: %d\n",CHAR_MAX); 15 | 16 | printf("*\n"); 17 | printf("Caracter sin signo\n"); 18 | printf("Mínimo: 0\n"); 19 | printf("Máximo: %u\n",UCHAR_MAX); 20 | 21 | printf("*\n"); 22 | printf("Short int con signo\n"); 23 | printf("Mínimo: %hi\n",SHRT_MIN); 24 | printf("Máximo: %hi\n",SHRT_MAX); 25 | 26 | printf("*\n"); 27 | printf("Short int sin signo\n"); 28 | printf("Mínimo: 0\n"); 29 | printf("Máximo: %hu\n",USHRT_MAX); 30 | 31 | printf("*\n"); 32 | printf("Long int con signo\n"); 33 | printf("Mínimo: %li\n",LONG_MIN); 34 | printf("Máximo: %li\n",LONG_MAX); 35 | 36 | printf("*\n"); 37 | printf("Long int sin signo\n"); 38 | printf("Mínimo: 0\n"); 39 | printf("Máximo: %lu\n",ULONG_MAX); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /variables/2_size/size_of: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/2_size/size_of -------------------------------------------------------------------------------- /variables/2_size/size_of.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void){ 6 | printf("Tamaño de datos básicos\n"); 7 | printf("=======================\n"); 8 | printf("Tipo\tTamaño en bytes\n"); 9 | printf("====\t===============\n"); 10 | 11 | printf("char\t%ld\n",sizeof(char)); //¿De qué tamaño es un char? 12 | printf("string\t%ld\n",sizeof(char[10])); //¿De qué tamaño es un char de 50 espacios (strings)? 13 | printf("int\t%ld\n",sizeof(int)); //¿De qué tamaño es un entero? 14 | printf("float\t%ld\n",sizeof(float)); //¿De qué tamaño es un flotante? 15 | printf("double\t%ld\n",sizeof(double)); //¿De qué tamaño es un flotante double? 16 | printf("double\t%ld\n",sizeof(double)); //¿De qué tamaño es un flotante double? 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /variables/3_types/asignacion_string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/3_types/asignacion_string -------------------------------------------------------------------------------- /variables/3_types/asignacion_string.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | //#include // Archivo de cabecera para subrutinas de utilidades 3 | #include // Archivo de cabecera para funciones cadena 4 | int main() 5 | { // Inicio 6 | //char saludo[10] = "Hola Mundo000000"; // Define variable cadena 7 | // 8 | //char nombre[50] = "Mariana Juarez Rosas"; 9 | char pais[3] = "MXN"; 10 | //char apellidoPaterno[50] = ""; 11 | //char apellidoMaterno[50] = ""; 12 | //strcpy(saludo,"Buenos"); // Asigna valor a cadena 13 | //strcat(saludo," dias"); 14 | //strcat(saludo,"_usuario"); 15 | //printf("%c\n",pais); // Muestra cadena nueva 16 | //printf("%i\n",pais); 17 | //printf("%s\n",pais); // Cadena de caracteres string 18 | //printf("\n%s\n",nombre); 19 | printf("\n%s\n",pais); 20 | return 0; 21 | } // Fin de programa 22 | -------------------------------------------------------------------------------- /variables/3_types/bool: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/3_types/bool -------------------------------------------------------------------------------- /variables/3_types/bool.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include// Boolean 3 | 4 | int main(){ 5 | //tipo_dato identificador = valor; 6 | bool reprobado = false; //true / false 7 | 8 | // if(false){} 9 | /* if(true){ 10 | 11 | } 12 | */ 13 | if(reprobado){ 14 | printf("Reprobaste el taller\n"); 15 | }else{ 16 | printf("Aprobaste con 6\n"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /variables/3_types/bool2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/3_types/bool2 -------------------------------------------------------------------------------- /variables/3_types/bool2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include// Booleanos 3 | 4 | bool esAdolescente(int edad); 5 | 6 | int main(){ 7 | bool Adolescente = esAdolescente(23); 8 | if(Adolescente){ 9 | printf("Nini"); 10 | }else{ 11 | printf("Consigue trabajo"); 12 | } 13 | } 14 | bool esAdolescente(int edad){ 15 | if(edad <= 18) return true; 16 | else return false; 17 | } 18 | -------------------------------------------------------------------------------- /variables/3_types/char: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/3_types/char -------------------------------------------------------------------------------- /variables/3_types/char.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char letra; // Carácter de una posición 4 | letra='@'; // Asigna valor 5 | 6 | //letra='\''; // Asigna valor 7 | // El caracter blackslash \ es un caracter de escape 8 | printf("La letra es %c. Su valor ASCII es %d\n",letra, letra); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /variables/3_types/int.c: -------------------------------------------------------------------------------- 1 | #include 2 | int letra; // Carácter de una posición 3 | int main() 4 | { 5 | int system(const char clear); 6 | letra='6'; // Asigna valor 7 | printf("La numero %d en ASCII es %c\n",letra,letra); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /variables/4_type_def/type_def: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/4_type_def/type_def -------------------------------------------------------------------------------- /variables/4_type_def/type_def.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | 4 | // Definición de nuevos tipos de datos 5 | typedef short int entero_corto; // Crea tipo de dato entero corto 6 | typedef float real; // Crea tipo de dato punto flotante de simple precisión 7 | typedef char jaimito; // Crea tipo de dato caracter 8 | // Uso de de nuevos tipos de datos 9 | 10 | //Declarar mis variables con el tipo de dato que definí 11 | //short int x; 12 | entero_corto x; 13 | //float y; 14 | real y; 15 | //char jaimito; 16 | jaimito letra; 17 | 18 | int main(){ 19 | x=32; 20 | y=22.2; 21 | letra='@'; 22 | printf("Entero Corto: %d Real: %0.2f Letra: %c\n",x,y,letra); 23 | return 0; 24 | } // Fin de programa 25 | -------------------------------------------------------------------------------- /variables/5_operators/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/5_operators/a.out -------------------------------------------------------------------------------- /variables/5_operators/incremento_decremento: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/5_operators/incremento_decremento -------------------------------------------------------------------------------- /variables/5_operators/incremento_decremento.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | //++ incremento 4 | //-- decremento 5 | int main(){ // Inicio 6 | float a,b; //Reservando espacio en memoria principal 7 | 8 | printf("Dame el primer número\n"); //Impresión en pantalla 9 | scanf("%f",&a); 10 | /* printf("Valor inicial de a = %f\n",a); //20.50 11 | b=++a; // b = 21.50; 12 | // a = a +1; a = 20.50 + 1 = 21.50 13 | // b = a; b= 21.50 14 | 15 | printf("Valor de b en el momento de hacer la operacion ++a = %f\n",b); //21 16 | printf("Valor de a después de hacer ++a = %f\n",a); //21 17 | */ 18 | 19 | printf("Valor inicial de a = %f\n",a); 20 | b=a++; // b = 20.50; a =21.50; 21 | // b = a; a = 21.50 b= 21.50; 22 | // a++ = 21.50 + 1; a= 22.50; 23 | printf("Valor de b en el momento de hacer la operación a++ = %f\n",b); 24 | printf("Valor de a después de hacer a++ = %f\n",a); 25 | /* 26 | printf("Valor inicial de a = %f\n",a); 27 | b=--a; 28 | printf("Valor de b en el momento de hacer la operación --a = %f\n",b); 29 | printf("Valor de a después de hacer --a = %f\n",a); 30 | printf("Valor inicial de a = %f\n",a); 31 | b=a--; 32 | printf("Valor de b en el momento de hacer la operación a-- = %f\n",b); 33 | printf("Valor de a después de hacer a-- = %f\n",a); 34 | */ 35 | return 0; 36 | } // Fin de programa 37 | -------------------------------------------------------------------------------- /variables/5_operators/operadores_logicos: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/5_operators/operadores_logicos -------------------------------------------------------------------------------- /variables/5_operators/operadores_logicos.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ // Inicio 5 | //system("clear"); // Limpia pantalla 6 | /* = asignación 7 | * == igualdad 8 | * != diferente 9 | * ! NOT 10 | * && AND (y) 11 | * ||(pipe) OR (o) 12 | */ 13 | /* 14 | */ 15 | 16 | int a = 10; 17 | int b = 10; 18 | int c =100; 19 | // (1 && 1) 20 | //printf("%i", !(((a==b) < c) && (b 30){ 24 | printf("Eres millenials"); 25 | 26 | }else{ 27 | printf("Eres baby boomer"); 28 | } 29 | 30 | 31 | 32 | 33 | 34 | //printf("!(((10 <= 1) AND (2==2)) OR (4==3)) ); devuelve %d \n", (!(((10 <= 1) && (2==2)) || (4==3))) ); 35 | /* 36 | printf("!(1 != 1) devuelve %d que implica verdadero\n",!(1 != 1) ); 37 | printf("!(1 == 1) devuelve %d que implica falso\n",!(1 == 1)); 38 | printf("1 == 1 && 2 == 2 devuelve %d que implica verdadero\n",1 == 1 && 2 == 2); 39 | printf("1 == 1 && 2 == 3 devuelve %d que implica falso\n",1 == 1 && 2 == 3); 40 | printf("1 == 1 || 2 == 3 devuelve %d que implica verdadero\n",1 == 1 || 2 == 3); 41 | printf("1 != 1 || 2 == 3 devuelve %d que implica falso\n",1 != 1 || 2 == 3); 42 | printf("1 >= 1 || 2 <= 3 devuelve %d que implica verdadero\n",1 >= 1 || 2 <= 3); 43 | printf("1 >= 1 || 2 >= 3 devuelve %d que implica verdadero\n",1 >= 1 || 2 >= 3); 44 | printf("'A' == 'A' devuelve %d que implica verdadero\n",('A' == 'A')); 45 | printf("'A' > '@' devuelve %d que implica falso\n",('A' > '@')); 46 | printf("'A' < 'B' devuelve %d que implica verdadero\n",('A' < 'B')); 47 | printf("'a' > 'A' devuelve %d que implica falso\n",('a' > 'A')); 48 | printf("'a' < 'A' devuelve %d que implica verdadero\n",('a' < 'A')); 49 | */ return 0; 50 | } // Fin de programa 51 | -------------------------------------------------------------------------------- /variables/5_operators/operadores_racionales: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/5_operators/operadores_racionales -------------------------------------------------------------------------------- /variables/5_operators/operadores_racionales.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | int main(){ // Inicio 4 | printf("2 == 2 devuelve %i \n",2==2); //true 1 5 | printf("2 !== 2 devuelve %i \n",2!=2); //true 1 6 | printf("2 > 2 devuelve %i \n",2>2); //true 1 7 | printf("2 < 2 devuelve %i \n",2<2); //true 1 8 | printf("2 <= 2 devuelve %i \n",2<=2); //true 1 9 | printf("2 !== 2 devuelve %i \n",2>=2); //true 1 10 | /*printf("'A' == 'a' devuelve %d que implica falso\n",'A'=='a'); 11 | printf("2 != 2 devuelve %d que implica falso\n",2!=2); 12 | printf("'A' != 'a' devuelve %d que implica verdadero\n",'A'!='a'); 13 | printf("'a' > 'b' devuelve %d que implica verdadero\n",'a'>'Z'); 14 | printf("'b' > 'a' devuelve %d que implica falso\n",'Z'>'a'); 15 | printf("'1' >= '1' devuelve %d que implica verdadero\n",'1'>='1'); 16 | printf(" 4 >= 5 devuelve %d que implica falso\n",4>=5); 17 | printf("'B' < 'A' devuelve %d que implica verdadero\n",'a'>'Z'); 18 | printf("'A' < 'B' devuelve %d que implica falso\n",'Z'>'a'); 19 | printf("6 <= 6 devuelve %d que implica verdadero\n",6<=6); 20 | printf("8 <= 7 devuelve %d que implica falso\n",8<=7); 21 | */ 22 | 23 | return 0; 24 | } // Fin de programa 25 | -------------------------------------------------------------------------------- /variables/6_read/fgets.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* Tamanio de nombre + 1. */ 6 | 7 | #define MAX_NAME_SZ 256 8 | 9 | int main() { 10 | 11 | char *name = malloc(MAX_NAME_SZ); 12 | if (name == NULL) { 13 | printf("No memory\n"); 14 | return 1; 15 | } 16 | 17 | /* Ask user for name. */ 18 | 19 | printf("Nombre completo: "); 20 | 21 | /* Get the name, with size limit. */ 22 | 23 | fgets(name, MAX_NAME_SZ, stdin); 24 | 25 | /* Remove trailing newline, if there. */ 26 | 27 | if ((strlen(name) > 0) && (name[strlen (name) - 1] == '\n')) 28 | name[strlen (name) - 1] = '\0'; 29 | 30 | /* Say hello. */ 31 | 32 | printf("Hola %s.\n", name); 33 | 34 | /* Free memory and exit. */ 35 | 36 | free (name); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /variables/6_read/get_put_char.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define STOP 'S' 5 | int main() 6 | { 7 | char ch; 8 | while ((ch =getchar())!=STOP){ 9 | putchar(ch); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /variables/6_read/scan.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | 4 | int num_cuenta; 5 | float promedio; 6 | char nombre[10]; 7 | 8 | int main() 9 | { // Inicio 10 | printf("Ingrese numero de cuenta:"); 11 | scanf("%d",&num_cuenta); 12 | printf("Ingrese promedio:"); 13 | scanf("%f",&promedio); 14 | printf("Ingrese nombre:"); 15 | scanf("%s",nombre); 16 | // Imprime el registro 17 | printf("Alumno : %d %0.3f %s\n",num_cuenta,promedio,nombre); 18 | return 0; 19 | } // Fin de programa 20 | -------------------------------------------------------------------------------- /variables/6_read/scanf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define PI 3.14159 3 | int main() 4 | { 5 | int r; 6 | float l, a; 7 | printf("Introduce radio (entero): "); 8 | scanf("%d", &r); 9 | l=2*PI*r; 10 | a=PI*r*r; 11 | printf("La longitud de la circunferencia vale %f\n", l); 12 | printf("El área del círculo vale %f\n", a); 13 | } 14 | -------------------------------------------------------------------------------- /variables/6_read/scanf2.c: -------------------------------------------------------------------------------- 1 | /* Programa de empleo de printf() y scanf() */ 2 | #include 3 | int main() 4 | { 5 | int edad; 6 | char nombre[20]; 7 | printf("Introduce nombre: \n"); 8 | scanf("%s", nombre); 9 | printf("Introduce edad: \n"); 10 | scanf("%d",&edad); 11 | printf("Tu nombre es %s y tienes %d años. \n", nombre, edad); 12 | } 13 | -------------------------------------------------------------------------------- /variables/7_operations/comparacion.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { // Inicio 7 | int x,y,z; // A ser usadas en la condición y resultado de la expresión 8 | char t; // Guarda resultado de expresión 9 | //system("clear"); 10 | x=9; 11 | y=7; 12 | //operador ternario 13 | z=(x < y) ? x:y; // Carga menor entre x e y en z 14 | printf("El menor entre %d y %d es %d\n",x,y,z); 15 | // Muestra resultado de la expresión condicional 16 | t=(x % 2 == 0) ? 'p':'i'; // Carga 'p' en t, sino carga 'i' 17 | printf("%d es %s\n",x,(t=='p') ? "par":"impar"); 18 | // De acuerdo a que t sea 'p o 'i', muestra "par" o "impar" 19 | x=10; // Carga x para analizar si es par o impar 20 | printf("%d es %s\n",x,(x % 2 == 0) ? "par":"impar"); 21 | // Si x % 2 == 0 retorna 1(verdadero) muestra "par", sino "impar" 22 | return 0; 23 | } // Fin de programa 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /variables/7_operations/comparacion_dos: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/7_operations/comparacion_dos -------------------------------------------------------------------------------- /variables/7_operations/comparacion_dos.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n1, n2, n3; 5 | printf( "\nDame el primer número (entero): "); 6 | scanf( "%d", &n1 ); 7 | printf( "\nDame el segundo número (entero): "); 8 | scanf( "%d", &n2 ); 9 | printf( "\nDame el segundo número (entero): "); 10 | scanf( "%d", &n3 ); 11 | if ( n1 > n2 && n2 > n3 || n1 > n2 && n1 > n3 ){ 12 | printf( "\n\t%d es mayor que %d y %d\n", n1, n2, n3 ); 13 | }else{ 14 | if ( n1 < n2 ) 15 | printf( "\n\t %d es mayor que %d\n", n2, n1 ); 16 | else 17 | printf( "\n %d y %d son iguales\n", n1,n2 ); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /variables/7_operations/conversion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taller-programacion/C/1272f7fd7ec5616c8eb9e1ce1c6818512a7cafef/variables/7_operations/conversion -------------------------------------------------------------------------------- /variables/7_operations/conversion.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int x=4; 7 | float y=2.2; 8 | float z; // Resultado real 9 | int u; // Resultado entero. 10 | z=x+y; // Conversión implicita sin perdida de datos 11 | printf("%d + %2.1f = %2.1f \n",x,y,z); 12 | u=x+y; // Conversión implicita con perdida de datos 13 | printf("%d + %2.1f = %d\n",x,y,u); 14 | y=2.0; // Nuevo valor 15 | u=x+(int)y; // Conversión explicita 16 | printf("%d + %2.1f = %d\n",x,y,u); 17 | // Conversiones explícitas mediante funciones} 18 | printf("Cadena: \"%s\" a punto flotante: \n%10.2f\n","12345.50",atof("12345.50")); // atof() 19 | printf("Cadena: \"%s\" a entero: %d\n","12345",atoi("12345")); // atoi() 20 | printf("Cadena: \"%s\" a entero largo: %ld\n","12345679012334",atol("12345679012334")); //atol() 21 | return 0; 22 | } // Fin de programa 23 | -------------------------------------------------------------------------------- /variables/8_conversion/conversion.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | char ch = '@'; //64 4 | int ent = 2; 5 | float flt = 20.00; 6 | double dbl = 400.1234323; 7 | 8 | int main() 9 | { // Inicio 10 | system("clear"); // Limpia pantallpa 11 | printf("Char / Entero = %d\n",ch / ent ); //ch pasa a int 12 | printf("Float * Double = %e\n",flt * dbl ); // flt pasa a double 13 | printf("Float + Entero = %f\n",dbl + ent ); // ent pasa a double 14 | // printf("Float + Entero = %d\n",dbl + ent ); // error 15 | 16 | printf("(Char / Entero) + (Float * Double) * (Float + Entero) = %f\n", (ch / ent)+(dbl + ent)*(dbl + ent)); 17 | 18 | return 0; 19 | } // Fin de programa 20 | -------------------------------------------------------------------------------- /variables/8_conversion/forced_conversion.c: -------------------------------------------------------------------------------- 1 | #include // Archivo de cabecera para subrutinas de e/s 2 | #include // Archivo de cabecera para subrutinas de utilidades 3 | int a = 2; 4 | int b = 4; 5 | float c; 6 | int main() 7 | { // Inicio 8 | c=(float)a+b; 9 | system("clear"); // Limpia pantallpa 10 | printf("C vale %f\n",c); 11 | return 0; 12 | } // Fin de programa 13 | --------------------------------------------------------------------------------