Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 45: Write a C++ program to find the first capital letter in a string.

#include<iostream>
using namespace std;

int main()
{
	string str;
	int flag=0;
	cout<<"\nenter a string : ";
	cin>>str;

	for(int i=0;str[i]!='\0';i++)
	{
		if(str[i]>=65&&str[i]<=90)
		{
			cout<<"\nfirst capital alphabet in a string is at position "<<i+1;
			flag=1;
			break;
		}
	}
	if(flag==0)
		cout<<"\nthere is no capital letter in this string!!";

	return 0;
}


If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.