Guest User

Untitled

a guest
Nov 20th, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. int powx(int a, int b)
  5. {
  6.     int c = a;
  7.     if (b == 0) return 1;
  8.     if (b == 1) return a;
  9.     b -= 1;
  10.     while (b > 0) {
  11.         a *= c;
  12.         b--;
  13.     }
  14.     return a;
  15. }
  16.  
  17.  
  18. int get_number()
  19. {
  20.     const n = 10;
  21.     int i, j, p, a[n], d, sign = 1, number;
  22.     char c;
  23.     number = 0;
  24.     for (i = 0; i < n; ++i) {
  25.         c = getchar();
  26.         if (c == '\n') return (-1);
  27.         if (isdigit(c) == true) {
  28.             a[i] = c - '0';
  29.         }
  30.         else if (c == '-' || c == '+') {
  31.             if (i != 0) return 0;
  32.             a[i] = '-';
  33.             if (c == '-') sign = -1;
  34.             if (c == '+') sign = 1;
  35.         }
  36.         else if ((c == 'C' || c == 'c') && i > 0) {
  37.             p = i-1;
  38.             if (a[0] == '-') {
  39.                 p = i-2;
  40.                 for (j = 1; j < i; ++j) {
  41.                     number += a[j] * powx(10,p);
  42.                     p--;
  43.                 }
  44.             }
  45.             else for (j = 0; j < i; ++j) {
  46.                 number += a[j] * powx(10,p);
  47.                 p--;
  48.             }
  49.             number *= sign;
  50.             return (9 * number / 5 + 32);
  51.         }
  52.         else return 0;
  53.     }
  54. }
  55.  
  56. int main()
  57. {
  58.     int i, m;
  59.     m = get_number();
  60.     while (m != (-1)) {
  61.         if (m != 0 && m != -1) printf("%dF ", m);
  62.         m = get_number();
  63.     }
  64.     printf("\n");
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment