1. /*
2. * C Program to find the first capital letter in a string using
3. * Recursion
4. */
5. #include <stdio.h>
6. #include <string.h>
7. #include <ctype.h>
8.
9. charcaps_check(char*);
10.
11. int main()
12. {
13. char string[20], letter;
14.
15. printf("Enter a string to find it's first capital letter: ");
16. scanf("%s", string);
17. letter =caps_check(string);
18. if(letter ==0)
19. {
20. printf("No capital letter is present in %s.\n", string);
21. }
22. else
23. {
24. printf("The first capital letter in %s is %c.\n", string, letter);}
25. return0;
26. }
27. charcaps_check(char*string)
28. {
29. staticinti=0;
30. if(i<strlen(string))
31. {
32. if(isupper(string[i]))
33. {
34. return string[i];
35. }
36. else
37. {
38. i=i+1;
39. returncaps_check(string);
40. }
41. }
42. elsereturn0;
43. }
output:
Enter a string to findit's first capital letter: iloveC
The first capital letter in iloveC is C.
2. * C Program to find the first capital letter in a string using
3. * Recursion
4. */
5. #include <stdio.h>
6. #include <string.h>
7. #include <ctype.h>
8.
9. charcaps_check(char*);
10.
11. int main()
12. {
13. char string[20], letter;
14.
15. printf("Enter a string to find it's first capital letter: ");
16. scanf("%s", string);
17. letter =caps_check(string);
18. if(letter ==0)
19. {
20. printf("No capital letter is present in %s.\n", string);
21. }
22. else
23. {
24. printf("The first capital letter in %s is %c.\n", string, letter);}
25. return0;
26. }
27. charcaps_check(char*string)
28. {
29. staticinti=0;
30. if(i<strlen(string))
31. {
32. if(isupper(string[i]))
33. {
34. return string[i];
35. }
36. else
37. {
38. i=i+1;
39. returncaps_check(string);
40. }
41. }
42. elsereturn0;
43. }
output:
Enter a string to findit's first capital letter: iloveC
The first capital letter in iloveC is C.
No comments:
Post a Comment