(1)
#include "stdio.h"
void change(int numsSource[][20], int numsDest[][20]){
char i,j,k;
for(i=0;i<20;i++)
for(j=0;j<20;j++)
numsDest[j][i]=numsSource[i][j];
}
int main(int argv,char *argc[]){
int a[20][20],b[20][20],n,i,j;
printf("Input n(int 0if(scanf("%d",&n)!=1 || n<1 || n>20){
printf("Input error, exit...\n");
return 0;
}
for(i=0;ifor(j=0;j scanf("%d",a[i]+j);
printf("%6d",a[i][j]);
}
printf("\n");
}
change(a,b);
printf("\nAfter the transpose:\n");
for(i=0;ifor(j=0;j printf("\n");
}
return 0;
}
运行样例:
(2)题意与输入、输出要求不符,就不做了吧?
(3)
#include "stdio.h"
#include
int main(int argv,char *argc[]){
int N,k,m,n,q,*p,t;
printf("Input N(int 0while(1){
if(scanf("%d",&N)!=1 || N<1 || N>100000){
if(N==0)
printf("You have chosen to quit...\n");
else
printf("Input error, exit...\n");
return 0;
}
if((p=(int *)malloc(sizeof(int)*N))==NULL){
printf("Application memory failure,exit...\n");
exit(0);
}
printf("Input %d integer(s)...\n",N);
for(m=0;mprintf("Input k(int N>=k>0)...\nk=");
scanf("%d",&k);
for(t=m=0;mfor(q=m,n=q+1;n if(p[q]>p[n])
q=n;
if(m!=q)
n=p[m],p[m]=p[q],p[q]=n;
printf("%6d",p[m]);
if(!t && k==p[m])
t=m+1;
}
printf("\n");
printf(t ? "It is at %d\n\n" : "No find...\n\n",t);
free(p);
}
return 0;
}
运行样例:
(4)
#include "stdio.h"
int main(int argv,char *argc[]){
int a[50],i,j,k,n;
printf("Input n(int 0while(1){
printf("n=");
if(scanf("%d",&n)!=1 || n<1 || n>49){
if(n==0)
printf("You have chosen to quit...\n");
else
printf("Input error, exit...\n");
return 0;
}
printf("Input %d integer(s)...\n",n);
for(i=0;iprintf("a[0] = %d\n",a[0]);
for(i=0;ifor(k=i,j=k+1;j if(a[k]>a[j])
k=j;
if(k-i)
j=a[k],a[k]=a[i],a[i]=j;
printf("%6d",a[i]);
}
printf("\n\n");
}
return 0;
}
运行样例: