导航:首页 > 编程语言 > 一行文字的编程题

一行文字的编程题

发布时间:2022-09-18 21:47:21

1. 编程题:输入一行文字,分别统计出其中英文大写字母、小写字母、空格、数字和其它字符的个数。(用指针和

#include <stdio.h>
#include <string.h>
void fun(char *p);
int main(){
char values[100];
int i;
gets(values);
fun(values);
return 0;
}
void fun(char *p){
int i;
int daxie=0;
int xiaoxie=0;
int kongge=0;
int shuzi=0;
int other=0;
//英文大写字母、小写字母、空格、数字和其它字符
for(i=0;i<strlen(p);i++){
if(p[i]>='A'&&p[i]<='Z')
daxie++;
else if(p[i]>='a'&&p[i]<='z')
xiaoxie++;
else if(p[i]==' ')
kongge++;
else if(p[i]>='0'&&p[i]<='9')
shuzi++;
else other++;
}
printf("大写字母:%d\n小写字母:%d\n空格:%d\n数字:%d\n其他字符:%d\n",daxie,xiaoxie,kongge,shuzi,other);

}

2. c语言编程题:输入一行字符,并以回车结束,将其中的小写字母转换成大写字母,其他字符不变。

/*功能:输入一行字符,并以回车结束,将其中的小写字母转换成大写字母,其他字符不变。*/
/*说明:改变N的大小可以改变输入字符串的范围大小*/

#include<stdio.h>
#include<string.h>
#define
N
100

int
main(void)
{
int
i,len;
char
str[N];
printf("Please
input
a
string:
");
gets(str);
len
=
strlen(str);
for(i=0;i<len;i++)
{
if(str[i]
>=
97
&&
str[i]
<=
122)
str[i]
=
str[i]
-
32;
else
str[i]
=
str[i];
}
printf("The
result
is
:
");
puts(str);

return
0;
}

给分吧。。。嘿嘿!!!!

3. c++编程题,让用户输入一行字符(空格分隔的多个单词),然后输出每一个单词(每行一个单词),求解

#include<iostream>

using namespace std;

void main() { char s[256],*p,*q; int b;

gets(s); p=s; while ( *p==' ' ) p++; //跳过前导空格

q=p;

while ( 1 ) {

b=0; while ( (*q!=' ')&&(*q!=0) ) q++;

if ( *q==0 ) b=1;

*q=0; q++; cout<<p<<endl;

if ( b ) break; else p=q;

}

}

4. c语言指针编程题:输入一行字符,将其中的每个字符从小到大排列后输出。

#include
#include

int main()
{
char str[5][80];
char temp[80];
int i,j;
printf("Please input 5 strings:\n");
for (i=0;i<5;i++)
{
gets(str[i]);
}
for (i=0;i<5;i++)
{
for (j=i+1;j<5;j++)
{
if (strcmp(str[i],str[j])>0)
{
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
}
printf("The strings:\n");
for (i=0;i<5;i++)
{
puts(str[i]);
}
return 0;
}
完美运行。好像我刚刚就做了一遍??
望采纳!!

5. 编程题:从键盘输入一行字符,分别统计字符中英文大写,小写,数字及其它字数的个数

在字符串后加'/'结束回车....
调试通过...
#include<stdio.h>
void main()
{
int i,zifu_x=0,zifu_d=0,shuzi=0,other=0;
char ch,p[100];
i=0;
printf("input strings(/ is end):");
do{
ch=getchar();
if(ch=='/')break;
p[i++]=ch;
}while(1);
p[i]=0;
i=0;
while(p[i++])
{
if(p[i-1]>'a'&& p[i-1]<'z')
{
zifu_x++;
continue;
}
if(p[i-1]>'A'&& p[i-1]<'Z')
{
zifu_d++;
continue;
}
if(p[i-1]>'0'&& p[i-1]<'9')
{
shuzi++;
continue;
}
other++;

}
printf("zifu_xiao=%d zifu_da=%d shuzi=%d other=%d",zifu_x,zifu_d,shuzi,other);
}

6. 编程题 2.输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。

#include"stdio.h"
void main()
{
char c;
int Zifu=0,Shuzi=0,Kongge=0,Others=0;
while((c=getchar())!='\n')
{
('A'<=c&&c<='Z'||'a'<=c&&c<='z')&&++Zifu;
'0'<=c&&c<='9'&&++Shuzi;
c==' '&&++Kongge;
!(('A'<=c&&c<='Z'||'a'<=c&&c<='z')||('0'<=c&&c<='9')||c==' ')&&++Others;

}
printf("字符数量为:%d,数字数量为:%d,空格数量为:%d,其他字符数量为:%d",Zifu,Shuzi,Kongge,Others);
return 0;
}

更好看点呢就这样
#include"stdio.h"
void main()
{
char c;
int Zifu=0,Shuzi=0,Kongge=0,Others=0;
while((c=getchar())!='\n')
{
('A'<=c&&c<='Z'||'a'<=c&&c<='z')&&++Zifu;
'0'<=c&&c<='9'&&++Shuzi;
c==' '&&++Kongge;
!(('A'<=c&&c<='Z'||'a'<=c&&c<='z')||('0'<=c&&c<='9')||c==' ')&&++Others;

}
printf("字符数量为:%d\n数字数量为:%d\n空格数量为:%d\n其他字符数量为:%d\n",Zifu,Shuzi,Kongge,Others);
return 0;
}

7. c语言编程:输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数,用while语句~~谢谢

#include <stdio.h>

int main()

{

int i=0, space=0, num=0, n=0, ch=0;

char s[20];

printf("请输入一串字符 ");

gets(s);

while(s[i] != '')

{

if(s[i]==' ')

space++;

else if(s[i]<='9' && s[i]>='0')

num++;

else if(s[i]<='z' && s[i]>='a' || s[i]<='Z' && s[i]>='A')

ch++;

else

n++;

i++;

}

printf("刚才输入的字符中英文字符个数为 %d ", ch);

printf("刚才输入的字符中空格个数为 %d ", space);

printf("刚才输入的字符中数字个数为 %d ", num);

printf("刚才输入的字符中其他个数为 %d ", n);

return 0;

}

(7)一行文字的编程题扩展阅读:

while 循环的格式:while (表达式){语句;}

while 循环的执行顺序:当表达式为真,则执行下面的语句,语句执行完之后再判断表达式是否为真,如果为真,再次执行下面的语句,然后再判断表达式是否为真……就这样一直循环下去,直到表达式为假,跳出循环。

例:

inta=NULL;

while(a<10){

a++;//自加

if(a>5)//不等while退出循环,直接判断循环

{break;//跳出循环}

}

结果: 结束后 a的值为6 。

8. C语言题目输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数。

错误代码:

if('a'<=nextchar<='z'||'A'<=nextchar<='Z')

else if('0'<=nextchar<='9')

修改后:

#include <stdio.h>

int main()

{

int letter=0,space=0,number=0,others=0;

char nextchar;

printf("Input your string ");

for(;nextchar!=' ';)

{

scanf("%c",&nextchar);

if('a'<=nextchar&&nextchar<='z'||'A'<=nextchar&&nextchar<='Z')

letter++;

else if(nextchar==' ')

space++;

else if('0'<=nextchar&&nextchar<='9')

number++;

else

others++;

}

printf("letter=%d,space=%d,number=%d,others=%d ",letter,space,number,others);

}

(8)一行文字的编程题扩展阅读

c++输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。

#include<cstdio>

int main()

{

char x[999];

int i,a=0,b=0,c=0,d=0;

gets(x);

for(i=0;i<=x[i];i++)

{

if('A'<=x[i]&&x[i]<='z')

a++;

else if('0'<=x[i]&&x[i]<='9')

b++;

else if(x[i]==' ')

c++;

else

d++;

}

printf("%d %d %d %d ",a,b,c,d);

return 0;

}

9. c语言编程题 .键盘输入一行字符,每一个字符存放在一个链表节点,按反序把这行字符打印出来

#include<stdio.h>
#include<string.h>
void printit(char *str,int length) //返序输出函数
{

int i;
for(i=length-1;i>=0;i--) //从给定的字符串的最后一位依次向前遍历各字符
putchar(*(str+i)); //每向前一个字符即打印该字符,直至第一个字符为止。
}
int main()
{ char str[80]=""; //定义一个长度为80字节的字符串数组,并初始化
gets(str); //从键盘中输入一个字符串(遇回车键结束)
printit(str,strlen(str)); //调用上面定义的函数反序输出字符串
printf("\n"); //输入一个回车换行符,使后续输出能另起一行
return 0;
}

10. 编程题: 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数。(分别使用wh

1 while语句:

#include<stdio.h>
int main(void)
{
//输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
char ch;
int char_num=0,kongge_num=0,int_num=0,other_num=0;
while((ch=getchar())!='\n')//回车键结束输入,并且回车符不计入
{
if(ch>='a'&&ch<='z'||ch<='z'&&ch>='a')
{
char_num++;
}
else if(ch==' ')
{
kongge_num++;
}
else if(ch>='0'&&ch<='9')
{
int_num++;
}
else
{
other_num++;
}
}
printf("字母= %d,空格= %d,数字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num);
return 0;
}

2 ,do while语句:

#include<stdio.h>
int main(void)
{
//输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
char ch;
int char_num=0,kongge_num=0,int_num=0,other_num=0;
do
{
if(ch>='a'&&ch<='z'||ch<='z'&&ch>='a')
{
char_num++;
}
else if(ch==' ')
{
kongge_num++;
}
else if(ch>='0'&&ch<='9')
{
int_num++;
}
else
{
other_num++;
}
} while((ch=getchar())!='\n')//回车键结束输入,并且回车符不计入
printf("字母= %d,空格= %d,数字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num);
return 0;
}

阅读全文

与一行文字的编程题相关的资料

热点内容
机票php源码 浏览:231
linux共享mac 浏览:922
中国没有国外的服务器地址 浏览:757
为什么退款服务器连接错误 浏览:555
android短信存储位置 浏览:970
unix网络编程卷4 浏览:808
找靓机app下单什么时候发货 浏览:413
android一个应用两个进程 浏览:802
linux硬盘复制 浏览:808
php图片服务器搭建 浏览:801
下载压缩文件怎么打开 浏览:194
新建文件夹叫什么名字 浏览:567
windows20的开机命令 浏览:334
微信一般在电脑的那个文件夹 浏览:511
go在win7下编译特别慢 浏览:256
光遇ios耳机安卓为什么没有 浏览:904
小米手机桌面文件夹经常自动散开 浏览:607
小米电话手表用什么app进行设置 浏览:265
虚拟打印机pdf下载 浏览:671
jdk编译运行方法 浏览:459