Run
#include <iostream>
using namespace std;
int main()
{
//Initializing variable.
char str[100];
int i, j;
//Accepting input.
cout<<"Enter a string : ";
gets(str);
//Iterating each character and removing non alphabetical characters.
for(i = 0; str[i] != '\0'; ++i)
{
while (!( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] == '\0') )
{
for(j = i; str[j] != '\0'; ++j)
{
str[j] = str[j+1];
}
str[j] = '\0';
}
}
//Printing output.
cout<<"After removing non alphabetical characters the string is :";
puts(str);
return 0;
}
Output:
Enter a string : *1prep_insta*
After removing non alphabetical characters the string is :prepinsta
#include
using namespace std;
int main(int argc, char const *argv[])
{
string str=”P*re;p..ins’t^a?”;
int n=str.length();
string res=””;
for(int i=0; i<n; i++){
if(isdigit(str[i]))
continue;
if(isalpha(str[i]))
res+=str[i];
else
continue;
}
cout<<res;
return 0;
}
Hey, Join our TA Support Group on Discord, where we will help you out with all your queries: Discord
Hey, Join our TA Support Group on Discord, where we will help you out with all your queries: Discord
#include
#include
using namespace std;
int main(){
string str;
cout<<"enter a string"<= ‘a’ && str[i] = ‘A’ && str[i] <= 'Z'))
{
cout<<str[i];
}
}
return 0;
}
//another simple solution
#include
#include
using namespace std;
int main ()
{
char ch[100];
cin>>ch;
int count=0;
int len=strlen(ch);
for(int i=0; i=’A’&& ch[i]=’a’&& ch[i]<='z'))
{
continue;
}
else
{
for(int j=i; j<len; j++)
{
ch[j]=ch[j+1];
}
len–;
i–;
}
}
cout<<ch;
}
#include
#include
using namespace std;
int main()
{
char a[100],b[100];
int i=0,j=0,k=-1;
gets(a);
for(i=0;a[i]!=’\0′;i++)
{
if(a[i]>=’a’&&a[i]=’A’&&a[i]<='Z')
{
k++;
a[k]=a[i];
}
else
{
continue;
}
}
a[k+1]='\0';
puts(a);
}