c-first-steps

a C playground
Index Commits Files Refs README
commit b9fdbd73357c92fd26635b75f77176f658b713aa
parent e7406a15e64c2483b214c22f9a5a784f6cd1f949
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date:   Thu, 19 Nov 2020 00:25:00 -0300

Added ../guia01/{ej1.c,ej2.c,ej8.c} as well as ../guia02/{ex11.c,ex18.c}

Diffstat:
A95.11/guia01/ej1.c | 39+++++++++++++++++++++++++++++++++++++++
A95.11/guia01/ej2.c | 15+++++++++++++++
A95.11/guia01/ej8.c | 27+++++++++++++++++++++++++++
A95.11/guia02/ex11.c | 39+++++++++++++++++++++++++++++++++++++++
A95.11/guia02/ex18.c | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 212 insertions(+), 0 deletions(-)
diff --git a/95.11/guia01/ej1.c b/95.11/guia01/ej1.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+
+#define DIVISA_NAME_ARS    "Pesos"
+#define DIVISA_NAME_BRL    "Reales"
+#define DIVISA_NAME_USD    "Dolares"
+#define DIVISA_NAME_EUR "Euros"
+
+#define MAX_DIVISAS    4
+
+typedef enum {
+    ARS, BRL, USD, EUR
+} divisa_t;
+
+
+int main( void ) {
+
+    divisa_t divisa_origen = ARS;
+    divisa_t divisa_final = USD;
+
+    float monto_origen, monto_final;
+
+    monto_origen = 1000;
+    
+
+
+    float divisas[MAX_DIVISAS][MAX_DIVISAS] = {
+        {1.000, 0.067, 0.012, 0.011},    //    ARS
+        {0.067, 1.000, 0.190, 0.160},    //    BRL
+        {0.012, 0.190, 1.000, 0.850},    //    USD
+        {0.011, 0.160, 0.850, 1.000}    //    EUR
+    };
+
+    monto_final = (monto_origen * divisas[divisa_origen][divisa_final]);
+    printf("%f\n", monto_final);
+
+    return 0;
+}
+
+
diff --git a/95.11/guia01/ej2.c b/95.11/guia01/ej2.c
@@ -0,0 +1,15 @@
+/*    Calculates the total resistance of a closed circuit    */
+
+#include <stdio.h>
+
+#define MAX_RESISTORS 7
+
+int main( void  ) {
+
+    int resistor[MAX_RESISTORS];
+
+
+
+
+    return 0;
+}
diff --git a/95.11/guia01/ej8.c b/95.11/guia01/ej8.c
@@ -0,0 +1,27 @@
+/*    Calculates the factorial of a given number.    */
+
+#include <stdio.h>
+
+#define ERR_MSG_NEG "ERR: The entered number is negative!"
+
+int main(void) {
+    
+    int fact, i, res;
+
+    printf("Enter a number: ");
+    if(scanf("%i", &fact) == EOF)
+        return 1;        
+
+    if(fact < 0) {
+        printf(ERR_MSG_NEG"\n");
+        return 1;
+    }
+
+    res = 1;
+    for(i = 1; i <= fact; i++) {
+        res *= i;
+    }
+
+    printf("%d! = %d\n", fact, res);
+    return 0;
+}
diff --git a/95.11/guia02/ex11.c b/95.11/guia02/ex11.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+
+
+#define TM            "3M Corporation"
+#define MAXWELL        "Maxwell Corporation"
+#define SONY        "Sony Corporation"
+#define VERBATIM     "Verbatim Corporation"
+
+typedef enum {
+    TM_CORPORATION            = '3',
+    MAXWELL_CORPORATION        = 'M',
+    SONY_CORPORATION        = 'S',    
+    VERBATIM_CORPORATION    = 'V'
+} manufacturer_t;
+
+
+int main(void) {
+    manufacturer_t c;
+    printf("Introduzca un Id. de fabricante: ");
+    c = getchar();
+    switch(c) {
+        case TM_CORPORATION:
+            printf(TM"\n");
+            break;
+        case MAXWELL_CORPORATION:
+            printf(MAXWELL"\n");
+            break;
+        case SONY_CORPORATION:
+            printf(SONY"\n");
+            break;
+        case VERBATIM_CORPORATION:
+            printf(VERBATIM"\n");
+            break;
+        default:
+            printf("El numero ingresado no es valido\n");
+            return 1;
+    }
+    return 0;
+}
diff --git a/95.11/guia02/ex18.c b/95.11/guia02/ex18.c
@@ -0,0 +1,92 @@
+#include <stdio.h>
+
+#define LANGUAGE GER    //    Define language in which month are displyed ESP,GER,ENG
+
+#if LANGUAGE == ESP
+    #define JANUARY        "ENERO"
+    #define FEBRUARY    "FEBRERO"
+    #define MARCH         "MARZO"
+    #define APRIL        "ABRIL"
+    #define MAYO        "MAYO"
+    #define JUNE        "JUNIO"
+    #define JULY        "JULIO"
+    #define AUGUST        "AGOSTO"
+    #define SEPTEMBER    "SEPTIEMBRE"
+    #define OCTOBER        "OCTUBRE"
+    #define NOVEMBER    "NOVIEMBRE"
+    #define DECEMBER    "DICIEMBRE"
+#elif LANGUAGE == GER 
+    #define JANUARY        "JANUAR"
+    #define FEBRUARY    "FEBRUAR"
+    #define MARCH         "MÄRZ"
+    #define APRIL        "APRIL"
+    #define MAYO        "MAI"
+    #define JUNE        "JUNI"
+    #define JULY        "JULI"
+    #define AUGUST        "AUGUST"
+    #define SEPTEMBER    "SEPTEMBER"
+    #define OCTOBER        "OKTOBER"
+    #define NOVEMBER    "NOVEMBER"
+    #define DECEMBER    "DEZEMBER"
+#else 
+    #define JANUARY        "JANUARY"
+    #define FEBRUARY    "FEBRUARY"
+    #define MARCH         "MARCH"
+    #define APRIL        "ABPRIL"
+    #define MAYO        "MAY"
+    #define JUNE        "JUNE"
+    #define JULY        "JULY"
+    #define AUGUST        "AUGUST"
+    #define SEPTEMBER    "SEPTEMBER"
+    #define OCTOBER        "OCTOBER"
+    #define NOVEMBER    "NOVEMBER"
+    #define DECEMBER    "DECEMBER"
+#endif
+
+typedef enum {
+    JAN, FEB, MAR, APR, MAY, JUN, JUL, AGO, SEP, OCT, NOV, DEC
+} mes_t;
+
+int main(void) {
+    mes_t mes = MAR;
+    switch(mes)
+    {
+        case JAN:
+            printf(JANUARY"\n");
+            break;
+        case FEB:
+            printf(FEBRUARY"\n");
+            break;
+        case MAR:
+            printf(MARCH"\n");
+            break;
+        case APR:
+            printf(APRIL"\n");
+            break;
+        case MAY:
+            printf(MAYO"\n");
+            break;
+        case JUN:
+            printf(JUNE"\n");
+            break;
+        case JUL:
+            printf(JULY"\n");
+            break;
+        case AGO:
+            printf(AUGUST"\n");
+            break;
+        case SEP:
+            printf(SEPTEMBER"\n");
+            break;
+        case OCT:
+            printf(OCTOBER"\n");
+            break;
+        case NOV:
+            printf(NOVEMBER"\n");
+            break;
+        case DEC:
+            printf(DECEMBER"\n");
+            break;
+    }    
+    return 0;
+}