第一篇:輸入一行字符,分別統(tǒng)計(jì)出其中英文、空格、數(shù)字和其他字符的個(gè)數(shù)
#include
int main()
{char ch;int A=0,B=0,C=0,D=0;
printf(“A(字符)B(空格)C(數(shù)字)D(其它):n”);
printf(“請(qǐng)輸入一串字符:”);
while((ch=getchar())!='n')
{if('a'<=ch && ch<='z' || 'A'<=ch && ch<='Z')A=A+1;
else if('0'<=ch&&ch<='9')C=C+1;
else if(ch==' ')B=B+1;
else D=D+1;
}
printf(“英文字母、空格、數(shù)字、其他字符的個(gè)數(shù)分別為:%d,%d,%d,%dn”,A,B,C,D);return 0;
}
第二篇:C#中鍵盤(pán)輸入一串字符,輸出該字符包含字母、數(shù)字個(gè)數(shù)
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
namespace study
{
class Program
{
static void Main(string[] args){
{
{
numberSum=}
{
smallSum=}
{
bigSum=}
{
elseSum=}
}
}
}
}
Console.WriteLine(“請(qǐng)輸入字符:”);string a = Console.ReadLine();int numberSum=0,smallSum=0,bigSum=0,elseSum=0;for(int i = 0;i < a.Length;i++)if(a[i] >= 48 && a[i] <= 57)numberSum+1;else if(a[i] >= 97 && a[i] <= 122)smallSum+1;else if(a[i] >= 65 && a[i] <= 90)bigSum+1;else elseSum+1;Console.WriteLine(“數(shù)字有{0}個(gè)”, numberSum);Console.WriteLine(“小寫(xiě)字母有{0}個(gè)”, smallSum);Console.WriteLine(“大寫(xiě)字母有{0}個(gè)”, bigSum);Console.WriteLine(“其他有{0}個(gè)”, elseSum);
第三篇:c語(yǔ)言編程 有一篇文章共有3行文字每行80個(gè)字符要求分別統(tǒng)計(jì)出其中英文字母數(shù)字空
C語(yǔ)言編程 有一篇文章,共有3行文字,每行80個(gè)字符。要求分別統(tǒng)計(jì)出其中英文字母,數(shù)字,空...2種做法,1種用單字符來(lái)讀取輸入,1種用字符串來(lái)讀取輸入。1.#include
while((c =
if('A' <= c && c <= 'Z')
else if('a' <= c &&
else if('0' <= c
else if(c == upper++;
c <= 'z')lower++;
&& c <= '9')' ')space++;
digit++;
else other++;printf(“upper:%dnlower:%dndigit:%dnspace:%dnother:%dn”, upper, lower, digit, space, other);return 0;} 2.#include
for(j = 0;str[i][j];j++)
gets(str[i]);
if('A' <= str[i][j]
upper++;&& str[i][j] <= 'Z')
else if('a' <= str[i][j] && str[i][j] <= 'z')lower++;
else if('0' <= str[i][j] &&
digit++;
else if(str[i][j] == ' ')str[i][j] <= '9')
space++;
else
other++;}printf(“upper:%dnlower:%dndigit:%dnspace:%dnother:%dn”, upper, lower, digit, space, other);return 0;}提問(wèn)人的追問(wèn)
2009-05-02 11:48
“for(j = 0;str[i][j];j++)”這一句沒(méi)有限制條件吧!是不是應(yīng)該寫(xiě)成“for(j=0;str[i][j]!='