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
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…