c语言编码函数
/*function: 测量字符串长度
*in: 需要测长度的字符串
*out: 字符串长度
*/
int strlen(string str)
{
assert( str != NULL ); // #include <assert.h>
char *ch = NULL;
int iLength = 0;
ch = str;
while ( *ch != '\0')
{
ch = ch + 1;
iLength = iLength + 1;
}
return iLength;
}
Ⅱ c语言函数编写
先写一个输入函数,把输入的名字存到变量name里面,调用函数seek(name);
子函数 string seek(string name)
循环比较name跟类数组中的名字,如果相同则return返回该同学数据,否则显示"no find"
照着写就行了,写了出错再问
Ⅲ c语言编写函数
#include <stdio.h>
#define M 30
#define N 10
typedef struct
{
int score[N];//选手的10个得分,得分与评委一一对应
double aver;//选手的平均分
char name[81];//选手的姓名
} Choice;
int inputChoice(Choice peo[],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
scanf("%s",peo[i].name);
for(j=0;j<n;j++)
scanf("%d",&peo[i].score[j]);
}
}
int sort(Choice peo[],int m,int n)
{
int i,j,k,t;
Choice temp;
for(i=0;i<n;i++)
{
peo[i].aver=0.0;
for(k=0;k<n-1;k++)
for(j=k+1;j<n;j++)
if(peo[i].score[k]>peo[i].score[j])
{
t=peo[i].score[k];
peo[i].score[k]=peo[i].score[j];
peo[i].score[j]=t;
}
for(j=1;j<n-1;j++)
peo[i].aver+=peo[i].score[j];
peo[i].aver/=n-2;
}
for(i=0;i<m-1;i++)
for(j=i+1;j<m;j++)
if(peo[i].aver<peo[j].aver)
{temp=peo[i];peo[i]=peo[j];peo[j]=temp;}
}
int main()
{
Choice peoples[M];
int m,n,i;
scanf("%d%d",&m,&n);
inputChoice(peoples,m,n);
sort(peoples,m,n);
for(i=0;i<3;i++)
printf("%s %.2lf
",peoples[i].name,peoples[i].aver);
return 0;
}
Ⅳ C语言函数编写
#include<stdio.h>
void Reverse(int arr[], int size);
int main()
{
int arr[10] = {0};
printf("请输入10个整数:\n");
for (int i=0; i<10; ++i)
{
scanf("%d", &arr[i]);
}
Reverse(arr, 10);
printf("反序:\n");
for (int i=0; i<10; ++i)
{
printf("%d ", arr[i]);
}
return 0;
}
void Reverse(int arr[], int size)
{
if (arr == NULL || size <=0)
return;
for (int beg=0, end=size-1; beg < end; ++beg, --end)
{
int tmp = arr[beg];
arr[beg] = arr[end];
arr[end] = tmp;
}
}
Ⅳ 用C语言编码实现strlen函数
根据题意可得如下代码:
#include<stdio.h>
intstrlen(char*s)
{
inti=0;
while(s[i]!='