9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
guia02/ex07.c (915B)
   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 #include <ctype.h>
   4 
   5 #define MAX_LEN 5    // max digits of the entered degree;
   6 #define ERR_MSG_LEN "El angulo ingresado contiene demasiados digitos"
   7 
   8 typedef enum {
   9     AGUDO, OBTUSO, RECTO
  10 } angulo_t;
  11 
  12 
  13 void clean(char *buffer)
  14 {
  15     for(size_t i = 0; i < MAX_LEN; i++)
  16         buffer[i] = '\0';
  17 }
  18 
  19 
  20 int main(void) {
  21     
  22     char buffer[MAX_LEN];
  23     clean(buffer);
  24     int c, d, e, i;
  25     i = 0;        
  26     while(((c = getchar()) != EOF) && c != '\n') {
  27         if(i < MAX_LEN) {
  28             buffer[i] = c;
  29             i++;
  30         } else if (i >= MAX_LEN) {
  31             fprintf(stderr, ERR_MSG_LEN"\n");
  32             return 1;
  33         }
  34     }
  35     d = atoi(buffer);
  36 
  37     if (d < 90)
  38         e = AGUDO;
  39     else if (d == 90)
  40         e = RECTO;
  41     else if (d > 90)
  42         e = OBTUSO;
  43 
  44 
  45     switch (e)
  46     {
  47         case AGUDO:
  48             printf("El angulo es AGUDO\n");
  49             break;
  50         case RECTO:
  51             printf("El angulo es RECTO\n");
  52             break;
  53         case OBTUSO:
  54             printf("El angulo es OBTUSO\n");
  55             break;
  56     }
  57     return 0;
  58 }
  59 
  60 
  61 
  62