求江苏省计算机二级vc++真题上机代码
发布网友
发布时间:2022-05-25 18:43
我来回答
共1个回答
热心网友
时间:2024-11-30 11:37
04年01
#include<stdio.h>
#include<string.h>
#define N 5
struct student
{char name[10];int score;
};
void sort(struct student stud[],int n)
{int i,j;
struct student p;
for(i=1;i<n;i++)
{p=stud[1];
for(j=i-1;j>=0&&p.score >stud[j].score ;j--)
stud[j+1]=stud[j];
stud[j+1]=p;
}
}
void main()
{struct student stud[N]={"aaa",60,"bbb",90,"ccc",85,"ddd",65,"yyy",77};
int i;
sort(stud,N);
printf("sorted data:\n");
for(i=0;i<0;i++)
printf("%s\t%d\n",stud[i].name ,stud[i].score );
}
04年02
#include<stdio.h>
#define M 3
#define N 4
int a[M][N]={14,9,7,12,17,29,46,32,72,86,57,60},max[M];
int search(int k,int *row,int *col)
{int i,j;
for(i=0;k>max[i]&&i<M;i++);
if(i<M)
{for(j=0;j<N;j++)if(k==a[i][j]){*row=i;*col=j;break;}
if(j>=N) return -1;
}else return -1;
}
void findmax(void)
{int i,j,t;
for(i=0;i<M;i++)
{t=a[i][0];for(j=1;j<N;j++)if(t<a[i][j]) t=a[i][j];
max[i]=t;}
}
main()
{int j,k,row,col;
findmax();
printf("You want to find:");scanf("%d",&k);
j=(k,&row,&col);
if(j!=-1)printf("Find the number in row %d col %d\n",row,col);
else printf("Not be found\n");
}
#include<stdio.h>
#define N 10
void crl(int *a)
{int i,j,max=0,min=0,temp;
for(i=1;i<N;i++)
if(a[min]>a[i]) min=i;
temp=a[min];
j=min;
while(j>0) {a[j]=a[j-1];j--;}
a[0]=temp;
for(i=1;i<N;i++)
if(a[max]<a[i]) max=i;
temp=a[max];
while(j<N-1) {a[j]=a[j+1];j++;}
a[N-1]=temp;
}
main()
{int a[N]={8,5,6,9,4,1,-1,7,3,2}; int i;
crl(a);
for(i=0;i<N;i++) printf("%5d",*(a+i));
printf("\n");
}
04年04
#include<stdio.h>
#include<string.h>
struct T {char name[20],num[20];};
struct T stu[5]={"cai","2106","li","4512","wang","6723","zhang","5129"};
int search(struct T items[],char name[],int n)
{int low=0,high=n-1,mid;
while(low<high)
{mid=(low+high)/2;
if(items[mid].name=name)
return mid;
else if(irems[mid].name<name)
low=mid+1;
else high=mid-1
}
return -1
}
int main(void)
{char name[30];int i;
printf("input the name:");scanf("%s",name);
i=search(stu,name,4);
if(i!=-1)printf("name:%c num:%c \n",stu[i].name,stu[i].num );
else printf(\nNot found!\n");
}
还有,只是没打完,下次有空吧