填空题
请补充函数proc(),该函数的功能是把数组arr中的奇数元素按原来的先后顺序放在原数组后面。
例如,原始数组为33 67 42 58 25 76 85 16 41 55,则输出结果为42 58 76 16 33 67 25 85 41 55。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define M 10
void proc(int arr[])
int i, j=0, k=0;
int bb[M];
for(i=0; i<M; i++)
if( (1) )
bb[k++]=arr[i];
else
arr[j++]=arr[i];
for(i=0; i<k; (2) )
arr[j]=bb[i];
void main()
int i;
int arr[M]=33, 67, 42, 58。25, 76, 85, 16, 41, 55;
system("CLS");
printf("\n***original list***\n");
for(i=0; i<M; i++)
printf("%4d", arr[i]);
proc(arr);
printf("\n***new list***\n");
for(i=0; i<M; i++)
printf("%4d", arr[i]);
【参考答案】
i++, j++
热门
试题
问答题
学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组S中,请编写函数proc(),它的功能是:把分数最高的学生数据放在h所指的数组中。注意:分数高的学生可能不只一个,函数返回分数最高学生的人数。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容。 试题程序: #include<stdio.h> #define M 16 typedef struct char num[10]; int s; STREC; int proc(STREC * a, STREC*b) void main() STREC stu[M]= GA005 , 85, GA003 , 76, GA002 , 69, GA004 , 85, GA001 , 91, GA007 , 72, GA008 , 64, GA006 , 87, GA015 , 85, GA013 , 91, GA012 , 64, GA014 , 91, GA011 , 66, GA017 , 64, GA018 , 64, GA016 , 72; STREC h[M]; int i, n; n=proc(stu, h); printf( The %d highest score: n , n); for(i=0; i<n; i++) printf( % S%4d n , h[i]. num, h[i].s); 输出最高分学生的学号和成绩 printf( n );