Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- int powx(int a, int b)
- {
- int c = a;
- if (b == 0) return 1;
- if (b == 1) return a;
- b -= 1;
- while (b > 0) {
- a *= c;
- b--;
- }
- return a;
- }
- int get_number()
- {
- const n = 10;
- int i, j, p, a[n], d, sign = 1, number;
- char c;
- number = 0;
- for (i = 0; i < n; ++i) {
- c = getchar();
- if (c == '\n') return (-1);
- if (isdigit(c) == true) {
- a[i] = c - '0';
- }
- else if (c == '-' || c == '+') {
- if (i != 0) return 0;
- a[i] = '-';
- if (c == '-') sign = -1;
- if (c == '+') sign = 1;
- }
- else if ((c == 'C' || c == 'c') && i > 0) {
- p = i-1;
- if (a[0] == '-') {
- p = i-2;
- for (j = 1; j < i; ++j) {
- number += a[j] * powx(10,p);
- p--;
- }
- }
- else for (j = 0; j < i; ++j) {
- number += a[j] * powx(10,p);
- p--;
- }
- number *= sign;
- return (9 * number / 5 + 32);
- }
- else return 0;
- }
- }
- int main()
- {
- int i, m;
- m = get_number();
- while (m != (-1)) {
- if (m != 0 && m != -1) printf("%dF ", m);
- m = get_number();
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment