In this article, we will discuss the concept of the C++ Program to count uppercase 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
Program 1
#include <iostream> #include <stdio.h> #include <conio.h> using namespace std; int main() { int i; int upper=0,lower=0;//variable declaration char ch[100];//array declaration cout<<"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++; } } cout<<"lowercase letters:" <<lower; cout<<"\nuppercase letters:"<<upper; getch(); return 0; }
When the above code is executed, it produces the following result
Enter the string: CPP Language lowercase letters:7 uppercase letters:4
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 <iostream> #include <conio.h> #include <stdio.h> using namespace std; int main() { int i; int upper=0,lower=0; char ch[100]; cout<<"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++; } cout<<"lowercase letters: "<<lower; cout<<"\nuppercase letters: "<<upper; getch(); return 0; }
When the above code is executed, it produces the following result
Enter the string: Count Upper Lower lowercase letters:12 uppercase letters:3
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 <iostream> #include <conio.h> #include <stdio.h> using namespace std; int main() { int i; int upper=0,lower=0; char ch[100]; cout<<"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); cout<<"lowercase letters: "<<lower; cout<<"\nuppercase letters: "<<upper; getch(); return 0; }
When the above code is executed, it produces the following result
Enter the string: UpperCase and LowerCase lowercase letters:12 uppercase letters:3
Approach
Suggested for you
Data type in C++ language
How to find reverse number using method In this article, we will discuss the concept…
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…