慕慕3371412
2018-07-27 12:24
#include <stdio.h>
#include<string.h>
#define N 5
#define M 10
int fun(char (*ss)[N][M],int k)
{
int i,j=0,len;
for(i=0;i<N;i++)
{
len=strlen(ss[i]);
if(len<=k)
strcpy(ss[j++],ss[i]);
}
return j;
}
int main()
{
char x[N][M]={"Beijing","Shanghai","Tianjing","Nanjing","Wuhan"};
int i,f;
printf("\nThe original string\n");
for(i=0;i<N;i++)puts(x[i]);
printf("\n");
f=fun(x,7);
printf("The string witch length is less than or equal to 7:\n");
for(i=0;i<f;i++)puts(x[i]);
printf("\n");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define N 10
int cmp(const void *a,const void *b){
return *(int*)b - *(int*)a;
}
int Sum(int score[]){
int s = 0,i;
for(i = 0 ; i < N ; i++)
s += score[i];
return s;
}
int Max(int score[]){
return score[0];
}
int Min(int score[]){
return score[N-1];
}
double Avg(int s){
return (s + 0.0) / N;
}
int main()
{
int score[N]={67,98,75,63,82,79,81,91,66,84};
int i,sum;
sum = Sum(score);
qsort(score,N,sizeof(int),cmp);//sort it
printf("Total score : %d\n",sum);
printf("Max score : %d\n",Max(score));
printf("Min Score : %d\n",Min(score));
printf("Average score : %f\n",Avg(sum));
printf("\n成绩排序:\n");
for(i = 0 ; i < N ; i++)
{
printf("Rank %d's score : %d\n",i+1,score[i]);
}
return 0;
}
这样呀。
C语言入门
926020 学习 · 20793 问题
相似问题