write a program to count the number of capital letters in an input string.
Answers
Answered by
2
isupper() function is to be used.
#include<iostream.h>
#include<ctype.h> // for the isupper() function
void main()
{
int count=0;
char string[10];
cin>>string;
for(int i=0;string[i]!='\0';i++)
{ if(isupper(string[i])) count++; }
cout<<"The Number of Upppercase letters is"<<string;
}
#include<iostream.h>
#include<ctype.h> // for the isupper() function
void main()
{
int count=0;
char string[10];
cin>>string;
for(int i=0;string[i]!='\0';i++)
{ if(isupper(string[i])) count++; }
cout<<"The Number of Upppercase letters is"<<string;
}
DeVasu:
"count" is to be printed on the last line instead of "string". Sorry for that
Answered by
5
string = input("Enter a string: ")
ccap = 0
for i in string:
if i.isupper():
ccap = ccap + 1
print("There are ", ccap, "upper case letters.")
isupper() is a string function that checks if a character is upper case or not.
Other similar functions:
- islower() - checks if a character is lower case or not.
- upper() - converts all characters into upper case.
- lower() - converts all characters into lower case.
- capitalize() - converts the first character in the string into upper case.
Similar questions