Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- int count_nums(char*);
- int main ()
- {
- char s[101];
- for (int anti_spam = 0; anti_spam < 101; anti_spam++)
- {
- s[anti_spam] = ' ';
- }
- printf("Please enter the text :\n");
- scanf("%c", &s[0]);
- if (s[0] == ' ')
- {
- printf("There are 0 nums\n");
- return 0;
- }
- for (int i = 1; i < 101; i++)
- {
- scanf("%c", &s[i]);
- if (s[i] == '\n')
- break;
- }
- int c = count_nums(s);
- printf("%c", c);
- printf("There are %d nums\n", c);
- return 0;
- }
- int count_nums(char *s)
- {
- if ((s[0] >= 48) && (s[0] <= 57) && ((s[1] >= 48) && (s[1] <= 57)))
- return count_nums(s+1);
- if ((s[0] >= 48) && (s[0] <= 57) && ((s[1] < 48) || (s[1] > 57)))
- return 1 + count_nums(s+1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement