Write a C program to print lowercase characters in a string using recursion.
#include <stdio.h>
#include <string.h>
/* print lowercase character in give character using recursion */
void printLower(char *str) {
if (*str != '\0') {
/* prints lowercase characters alone */
if (*str >= 'a' && *str <= 'z') {
printf("%c", *str);
}
printLower(str + 1);
}
return;
}
int main() {
char str[256];
/* get the input string from the user */
printf("Enter your input string:");
fgets(str, 256, stdin);
str[strlen(str) - 1] = '\0';
/* prints lowercase character in the given input */
printf("Lower case characters in given string:");
printLower(str);
printf("\n");
return 0;
}
#include <string.h>
/* print lowercase character in give character using recursion */
void printLower(char *str) {
if (*str != '\0') {
/* prints lowercase characters alone */
if (*str >= 'a' && *str <= 'z') {
printf("%c", *str);
}
printLower(str + 1);
}
return;
}
int main() {
char str[256];
/* get the input string from the user */
printf("Enter your input string:");
fgets(str, 256, stdin);
str[strlen(str) - 1] = '\0';
/* prints lowercase character in the given input */
printf("Lower case characters in given string:");
printLower(str);
printf("\n");
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input string:HeLlO WoRlD
Lower case characters in given string: elol
Enter your input string:HeLlO WoRlD
Lower case characters in given string: elol
No comments:
Post a Comment