Wednesday, October 31, 2018

STRING: PROGRAM TO COUNT NUMBER OF CHARACTER, DIGIT, SPECIAL SYMBOL IN A STRING

#include<stdio.h>
void main()
{
char str[30];
int i,ca=0,cd=0,cs=0;
printf("Enter the string:");
gets(str);
for(i=0;str[i]!='\0';i++)
{
if((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z'))
{
ca++;
}
else if(str[i]>='0' && str[i]<='9')
{
cd++;
}
else
{
cs++;
}
}
printf("number of character in a string: %d",ca);
printf("\nnumber of digits in a string: %d",cd);
printf("\nnumber of special character in a string: %d",cs);
}

No comments:

Post a Comment

Static Member Function

CODE : #include<iostream> using namespace std; class test  {     int code;       static int count;               //static...