帮忙解决2道C题目

来源:百度知道 编辑:UC知道 时间:2024/05/23 02:10:06
1.从键盘输入一个字符串,统计其中大写英文字母的个数与小写英文字母的个数。程序中设计了一个完成此统计功能的函数sti( )。请根据main( )函数的相关语句写出此函数的定义。
#include <stdio.h>
#include <string.h>
main( )
{
char a[1000];
int nd,nx=0
printf("input a string :\n");
scanf(“%s”, a);
sti(&nd, &nx, a, strlen(a)); //提示:nd与nx的作用见下一条语句
printf("大写字母 %d 个,小写字母%d 个\n"nd , nx);
}

2. 从键盘输入10个整数,然后按从大到小的顺序排序,最后输出排序后的结果。程序中设计了一个对n个整数进行排序的函数sort( )。请根据题目中给出的函数原型及其说明,应用此函数写出完成题目要求功能的main( )函数。
函数原型:void sort( int *a , int n );
说明:功能:对n个整数进行排序。
参数:a:待排序数组,n:a中整数个数。

/*
输入一行文字,找出其中大写字母,小写字母,空格,数字,及其他字符各有多少个.
*/
#include <iostream>

int main()
{
int upper = 0,
lower = 0,
digit = 0,
space = 0,
other = 0,
i = 0;
char* p;
char s[20];

std::cout<<"Input string: ";

while ((s[i] = std::cin.get()) != '\n')
{
i++;
}
p = &s[0];
while (*p != '\n')
{
if (('A' <= *p) && (*p <= 'Z'))
{
++upper;
}
else if (('a' <= *p) && (*p <= 'z'))
{
++lower;
}
else if (' ' == *p)
{
++space;
}
else if ((*p <= '9') && (*p >= '0'))
{
++digit;
}
else
{
++other;
}
p++;
}
std::cout<<"upper case: "<<upper<<std::endl;
std::cout<<"lower case: &qu