首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列给定程序中,fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。 例如,给字符串s输入:AAaaBBbb123 CCcccd,则应输出: upper=6,lower=8。请改正程序中的错误,使它得出正确的结果。 注意:
下列给定程序中,fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。 例如,给字符串s输入:AAaaBBbb123 CCcccd,则应输出: upper=6,lower=8。请改正程序中的错误,使它得出正确的结果。 注意:
admin
2019-04-04
14
问题
下列给定程序中,fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。
例如,给字符串s输入:AAaaBBbb123 CCcccd,则应输出:
upper=6,lower=8。请改正程序中的错误,使它得出正确的结果。
注意:部分源程序在文件MODI1.C中,不要改动mlun函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
/*********found*********/
void fun ( char *s, int a, int b )
{
while ( *s)
{if(*s>=’A’&&*s<=’Z’)
/*********found*********/
* a= a +1 ;
if(*s>=’a’&&*s<=’Z’)
/*********found*********/
*b=b+1;
s ++ ;
}
}
main ()
{ char s[100]; int upper = 0,
lower = 0 ;
printf ( "\nPlease a string : " );
gets ( s );
fun ( s, & upper, &lower );
printf ( " \n upper =% d lower
=%d\n", upper, lower ) ;
}
选项
答案
(1)void fun(char *s,int *a,int *b) (2)*a=*a+1; (3)*b=*b+1;
解析
(1)由主函数中调用fun函数的语句fun(s,&upper.&lower)可知,函数的后两个变量为指针的形式,所以用*a和*b。
(2)*a的作用是用来记录大写字母的个数,此处的作用是对*a累加1,所以此处应改为*a=**+1。
(3)*b的作用是用来记录小写字母的个数,此处的作用是对*b累加1,所以此处应改为*b=*b+1。
转载请注明原文地址:https://kaotiyun.com/show/m9Rp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
对下述程序的判断中,正确的是()。#include<stdio.h>voidmain(){char*P,s[256];p=s;while(strcmp(s,"theend")){printf("
在长度为64的有序线性表中进行顺序查找,最坏情况下需要比较的次数为
以下非法的赋值语句是()。
数据库管理系统中用来定义模式、内模式和外模式的语言为
以下程序用于判断a、b、c能否构成三角形,若能,输出YES,否则输出NO。当给a、b、c输入三角形三条边长时,确定a、b、c能构成三角形的条件是需同时满足三个条件:a+b>c,a+c>b,b+c>a。请填空。main(){floa
以下叙述中错误的是
以下程序段中与语句k=a>b?(b>c?1:0):0;功能等价的是______。
数据存储和数据流都是__________,仅仅是所处的状态不同。
下列字符数组初始化语句中,不正确的是()。
组成C语言程序的是()。
随机试题
女,37岁。突发心悸10分钟,心电图示心率164次/分,P波与QRS波无固定关系,QRS波时限≥0.12秒,可见室性融合波。最可能的诊断是()
业主或投资商的建设项目遇到承包商缺乏合作诚意会引发()。
根据税收征收管理法律制度的规定,关于发票等涉税资料的保存期限,下列说法正确的是()。
儿童一进商场就被漂亮的玩具吸引,这一刻出现的心理现象是()。
A.舌动脉分支B.面动脉分支C.上颌动脉分支D.颞浅动脉分支E.颞浅动脉分支颏动脉属于()。
有下面4条路由,202.204.19.0/24、202.204.24.0/24、202.204.32.0/24和202.204.13.0/24,如果进行路由汇聚,能覆盖这4条路由的地址是______。
有如下程序:#inc1ude<iostream>#inc1ude<cmath>usingstd::cout;classPoint{public:frienddoubledistance
能够实现从指定记录集里检索特定字段值的函数是( )。
WhatdoesAnnmean?
Successinlifedoesnotdependsomuchonone’sschoolrecord______onone’shonestyanddiligence.
最新回复
(
0
)