c语言函数题目

来源:百度知道 编辑:UC知道 时间:2024/07/02 04:50:13
【题目1】
函数f的功能是计算指定字符串中大写字母的个数以及小写字母的个数。请编写函数f,并设计main函数,以测试f的功能。
要求:
在实验报告中针对函数f进行算法分析并绘制流程图。
提示:
1)为了对f函数进行测试,main函数需要包括的功能主要有:字符串的输入、存储、对f函数的调用、大小写字母个数的输出等。
2)测试字符串中应该包括随机排列的大写、小写字母、数字字符、其他符号

【题目2】
如果函数main中定义了int a[N],请编写函数g,将数组a中的数据逆序,并在函数main中测试。例如数组中原来的内容是{0, 1, 2, 3, 4, 5},则逆序后将变成{5, 4, 3, 2, 1, 0}。

第一题:
#include<stdio.h>
#include<string.h>
void f(char str[80])
{
int i,count1=0,count2=0,count3=0,k;
k=strlen(str);
for(i=0;i<k;i++)
{
if(str[i]<'Z'&&str[i]>'A')
count1++;
if(str[i]<'z'&&str[i]>'a')
count1++;
else
count3++;
}
printf("大写字母的个数:%d\n",count1);
printf("小写字母的个数:%d\n",count2);
printf("其他字符的个数:%d\n",count3);

}
void main()
{
char str[80];
gets(str);
f(str);
}

第二题:
#include<stdio.h>
#define N 5
void g(int a[N])
{
int i,temp;
for(i=0;i<N;i++)
{
temp=a[i];
a[i]=a[N-i-1];
}
}
void main()
{
int i,a[N];
printf("请输入数组a:");
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
printf(&