#include <stdio.h>void main(){ int a = 0, b = 0, c = 0; int i = 0; char d[50] = ""; scanf("%s", d); while(d[i] != '\0') { if(d[i] >= 65 && d[i] <= 90) a++; else if(d[i] >=97 && d[i] <= 122) b++; else if(d[i] >= 48 && d[i] <= 57) c++; i++; } printf("大写字母:%d 小写字母%d 数字%d\n", a, b, c);}
#include <stdio.h>#include <stdlib.h>int main(){int little=0,large=0,num=0;char ch;ch=getchar();while(ch!='\n'){if(ch>='A'&&ch<='Z')large++;else if(ch>='a' && ch<='z')little++;else if(ch>='0'&&ch<='9')num++;ch=getchar();}printf("大写:%d\n小写:%d\n数字:%d\n",large,little,num);system("pause");return 0;}
#include <iostream> using namespace std; int main() { char c; int lettersmall=0,letterbig=0, digit=0; cout<<"please enter one line:"<<endl; while((c=getchar())!='\n') //当输入不是空格{ if(c>='a'&&c<='z') //小写lettersmall++; else if(c>='A'&&c<='Z') //大写letterbig++; else if(c>='0'&&c<='9') //数字digit++; } cout<<"lettersmall:"<<lettersmall<<",letterbig:"<<letterbig<<",digit:"<<digit<<endl; return 0; }
#include<iostream>#include<cstring>usingnamespacestd;voidmain(){charstr[100];intcount1=0,count2=0,count3=0;cout<<"inputthestring:"<<endl;cin>>str;intsize=strlen(str);inti=0;while(i<size){if(str[i]>='a'&&str[i]<='z')count1++;if(str[i]>='A'&&str[i]<='Z')count2++;if(str[i]>='0'&&str[i]<='9')count3++;i++;}cout<<"thestirnghaslowercaseletter'samount:"<<count1<<endl;cout<<"thestirnghascapitalletter'samount:"<<count2<<endl;cout<<"thestirnghasdigitalletter'samount:"<<count3<<endl;}