Chapter 5:
Conditional Structures
Programming Exercise
Problem # 1:
Writing a program that accepts a character and determines whether the character is a lowercase letter. A lowercase letter is any character that is greater than equal to 'a' and less than or equal to 'z'. If the entered character is a lowercase letter, display the message "Entered character is a lowercase letter", otherwise display the message "Entered character is not a lowercase letter".
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
char c;
cout<<"enter a character:";
cin>>c;
if(c>='a'&&c<='z')
cout<<"\nEntered character is a lower case letter";
else
cout<<"\nEntered character is not a lower case letter";
return 0;
}
#include<conio.h>
using namespace std;
int main ()
{
char c;
cout<<"enter a character:";
cin>>c;
if(c>='a'&&c<='z')
cout<<"\nEntered character is a lower case letter";
else
cout<<"\nEntered character is not a lower case letter";
return 0;
}
Code Screenshot:
Output:
Let me know in the comment section if you have any question.
Previous Post:
28. Program that inputs marks obtained by a student in five subjects. It then calulates and dispays the total marks and percentage.
Comments
Post a Comment