Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. int count_nums(char*);
  6. int main ()
  7. {
  8. char s[101];
  9. for (int anti_spam = 0; anti_spam < 101; anti_spam++)
  10. {
  11. s[anti_spam] = ' ';
  12. }
  13. printf("Please enter the text :\n");
  14. scanf("%c", &s[0]);
  15. if (s[0] == ' ')
  16. {
  17. printf("There are 0 nums\n");
  18. return 0;
  19. }
  20. for (int i = 1; i < 101; i++)
  21. {
  22. scanf("%c", &s[i]);
  23. if (s[i] == '\n')
  24. break;
  25. }
  26. int c = count_nums(s);
  27. printf("%c", c);
  28. printf("There are %d nums\n", c);
  29. return 0;
  30. }
  31. int count_nums(char *s)
  32. {
  33. if ((s[0] >= 48) && (s[0] <= 57) && ((s[1] >= 48) && (s[1] <= 57)))
  34. return count_nums(s+1);
  35. if ((s[0] >= 48) && (s[0] <= 57) && ((s[1] < 48) || (s[1] > 57)))
  36. return 1 + count_nums(s+1);
  37. return 0;
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement