Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <math.h>
- #ifndef DEBUG
- #define DEBUG(...)printf(_VA_ARGS_)
- #endif
- float stringtofloat(char *broj) {
- float temp = 0;
- int cnt = -1, neg = 0;
- while (*broj) {
- if (*broj == '.') {
- cnt = 0;
- }
- if (*broj == '-') {
- neg = 1;
- }
- if (isdigit(*broj)) {
- temp *= 10;
- temp = temp + (*broj - '0');
- if (cnt >= 0) {
- cnt++;
- }
- }
- broj++;
- }
- if (cnt > -1) {
- temp = temp / pow(10, cnt);
- }
- if (neg == 1) {
- temp = 0 - temp;
- }
- return temp;
- }
- int main() {
- int n = 0;
- char broj[11];
- scanf("%d", &n);
- for (int i = 0; i < n; i++) {
- scanf("%s", broj);
- printf("%.3f\n", stringtofloat(broj));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement