In this article, we will discuss the concept of the C Program for count upper or lowercase letter of the given string
In this post, we are going to learn how to count upper and lower case letters in a given string in C programming language
The program allows to enter a String and then it counts and displays whether the number of upper case and lower case letters of the given string using for loop in C language
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int i; int upper=0,lower=0; char ch[100]; printf("Enter the String:\n"); gets(ch); for(i=0; ch[i]!=0; i++){ if(ch[i]>='A' && ch[i]<='Z'){ upper++; } else if(ch[i]>='a' && ch[i]<='z'){ lower++; } } printf("lowercase letters: %d",lower); printf("\nuppercase letters: %d",upper); getch(); return 0; }
When the above code is executed, It produces the following result
Enter the String C language lowercase letters: 7 uppercase letters:2
Approach
The program allows to enter a String and it counts and displays whether the number of upper case and lower case letters of the given string using while loop in C language
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int i; int upper=0,lower=0; char ch[100]; printf("Enter the String:\n"); gets(ch); i=0; while(ch[i]!=0){ if(ch[i]>='A' && ch[i]<='Z'){ upper++; } else if(ch[i]>='a' && ch[i]<='z'){ lower++; } i++; } printf("lowercase letters: %d",lower); printf("\nuppercase letters: %d",upper); getch(); return 0; }
When the above code is executed, It produces the following result
Enter the String C Program for Upper Lower lowercase letters: 17 uppercase letters:7
Approach
The program allows to enter a String and it counts and displays whether the number of upper case and lower case letters of the given string using do-while loop in C language
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int i; int upper=0,lower=0; char ch[100]; printf("Enter the String:\n"); gets(ch); i=0; do{ if(ch[i]>='A' && ch[i]<='Z'){ upper++; } else if(ch[i]>='a' && ch[i]<='z'){ lower++; } i++; }while(ch[i]!=0); printf("lowercase letters: %d",lower); printf("\nuppercase letters: %d",upper); getch(); return 0; }
When the above code is executed, It produces the following result
Enter the String C is a procedural language lowercase letters: 19 uppercase letters:3
Approach
Suggested for you
Similar post
Java Program for count upper or lowercase letter of the given string
C Program for count upper or lowercase letter of the given string
Program for count upper or lowercase letter of the given string
Python Program for count upper or lowercase letter of the given string
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…