1.

Write a program to input a string and find the number of uppercase letters, lowercase letters, digits, special characters and white spaces.

Answer»

#include<iostream>

#include<cstdio>

using namespace std; 

int main() 

char line[100];

int i,digit=0, Ualpha=0, Lalpha=0, special=0, wspace=0; 

cout<<“Enter a string:”;

gets(str); 

for(i=0;str[i]!=’\0′;i++) 

if(str[i]>>=48 && str[i]<=57)

digit++;

else if(str[i]>65 && str[i]<=90)

Ualpha++; 

else if(str[i]>=97 && str[i]<=122) 

Lalpha++; 

else if(str[i]==’ ‘ || str[i]==’\t’) 

wspace++; 

else

special++; 

cout<<“The number of alphabets is “<<Ualpha+Lalpha<<

” the number of Uppercase letters is“<<Ualpha<< ” the number of Lowercase letters is “<<Lalpha<<” the number of digits is “<<digit<<” the special characters is“<<special<<” and the number of white spaces is “<<wspace; 

}



Discussion

No Comment Found

Related InterviewSolutions