求救C语言高手!!

2024-11-09 06:37:31
推荐回答(4个)
回答1:

给你写个把,下面是程序代码

#include
int main()
{
int ch;
int num=0,count=0,other=0;
printf("Input a string:\n");
while((ch=getchar())!='\\')
{
if(ch<='9'&&ch>='0')
num++;
else if(ch=='+'||ch=='-'||ch=='*'||ch=='/'||ch=='%'||ch=='=')
count++;
else
other++;
}
printf("0~9的数字有:%d个\n乘除加减取模赋值运算符有:%d个\n其他字符有:%d个\n",num,count,other);

}

回答2:

#include "stdafx.h"
#include "conio.h"

main()
{
char buff[200];
int n = 0;
int m = 0;
int j =0;
int k = 0;
int l = 0;
while(1)
{
char cTem;
cTem = getch();
if (cTem == 0x5C)
{
if (n==0)
{
break;
}
else
{
for (m=0;m {
if (buff[m] >= '0' && buff[m] <= '9')
{
j += 1;
}
else if (buff[m] == '+' ||
buff[m] == '-' ||
buff[m] == '*' ||
buff[m] == '/' ||
buff[m] == '%' ||
buff[m] == '=' )
{
k += 1;
}
else
{
l += 1;
}

}
}
break;

}
else
{
buff[n] = cTem;
n += 1;
}
}
printf("NO1: %d\n", j);
printf("NO2: %d\n", k);
printf("NO3: %d\n", l);
}

回答3:

题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
1.程序分析:利用while语句,条件为输入的字符不为'\n'.

2.程序源代码:
#include "stdio.h"
#include "conio.h"
main()
{
char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
getch();
}
粘个现成的,自己改一下,改一点就行了

回答4:

再加10分,我帮你做!