Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Wednesday, September 7, 2016

PROGRAM TO FIND NUMBER OF CHARACTERS IN A STRING:
#include<iostream>
#include<cstring>
using namespace std;
main()
{
char a[100];
int l;
cout<<"ENTER STRING";
cin.getline(a,100);
l=strlen(a);
cout<<"\nTOTAL CHARACTERS ARE "<<l;
}

Monday, September 5, 2016

C++  PROGRAM TO CHECK GIVEN STRING IS IN PALLINDROME OR NOT:


#include<iostream>
#include<cstring>
using namespace std;
class PALLINDROME
{
 char str1[100],str2[100];
 public:
  PALLINDROME()
  {
  cout<<"ENTER A STRING ";
  cin>>str1;
 
}
void reverse()
{
strcpy(str2,str1);
strrev(str2);
if(strcmp(str1,str2)==0)
{
cout<<"STRING "<<str1<<" IS IN PALLINDROME";

}
else
{
cout<<"STRING "<<str1<<" IS NOT IN PALLINDROME";
}
}
};
main()
{
PALLINDROME p;
p.reverse();
}






Friday, September 2, 2016

PROGRAM TO FIND NO OF CHARACTERS,DIGITS,SPACES,SPECIAL CHARACTERS IN A STRING :)
#include<iostream>
#include<cstring>
using namespace std;
main()
{  static int i,c,a,d,sp,sc;
string s;

cout<<"ENTER THE string";
getline(cin,s);
cout<<s;
while(s[i]!='\0')
{
if(s[i]>='A'&&s[i]<='z')
{
c++;}
else if(s[i]>='1'&& s[i]<='9')
{
d++;}
else if(s[i]==' ')
sp++;
else
{
sc++;}
i++;
}
cout<<"\nCHARACTERS "<<c;
cout<<"\nSPECIAL CHARACTERS "<<sc;
cout<<"\nDIGITS"<<d;
cout<<"\n SPACES"<<sp;
}