脚本宝典收集整理的这篇文章主要介绍了第八次作业,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1.字符串长度。
#include<stdio.h>
main()
{
char str[80];
int i=0;
int length=0;
gets(str);
puts(str);
while(str[i++]!='')
length++;
printf("字符串的长度为:%dn",length);
}
2.字符串中大写字母个数。
#include<stdio.h>
main()
{
char str[20];
int i,cnt;
cnt=i=0;
gets(str);
while(str[i]!='')
{
if(str[i]>='A'&&str[i]<='Z')
cnt++;
i++;
}
printf("大写字母个数为i:%dn",cnt);
}
3.去掉字符串中所有的*号。
#include<stdio.h>
main()
{
char str[20];
int i,j;
i=j=0;
gets(str);
while(str[i]!='n')
{
if(str[i]!='*')
str[j++]=str[i];
i++;
}
i=0;
while(i<j)
putchar(str[i++]);
}
4.a复制到不,要求每三个字符 插入一个空格。
#include<stdio.h>
main()
{
char a[20],b[20];
int i,j;
gets(a);
for(i=j=0;a[i]!='';i++)
{
b[j++]=a[i];
if((i+1)%3==0)
b[j++]=' ';
}
b[j]='';
puts(b);
}
5输入字符串中位置为奇数,ASCII为偶数的字符。
#include<stdio.h>
main()
{
char str[80];
int i=0;
gets(str);
while(str[i]!='')
{
if((i+1)%2==1&&str[i]%2==0)
putchar(str[i]);
i++;
}
}
5统计字符串中各数字字符的个数。
#include<stdio.h>
main()
{
char str[80];
int cnt[10]={0};
int i=0;
gets(str);
while(str[i]!='')
{
if(str[i]>='0'&&str[i]<='9')
cnt[(str[i]-'0')%10]++;
i++;
}
for(i=0;i<=9;i++)
printf("数字字符%d:%d个n",i,cnt[i]);
}
以上是脚本宝典为你收集整理的第八次作业全部内容,希望文章能够帮你解决第八次作业所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。