for(i=n-1;i>=0;i--){
a[i+1]=a[i];
}
a[0]=m;
}
if(m>a[n-1]){
a[n]=m;
}
for(i=0;iif(a[i]m){
for(j=n-1;j>=i+1;j--){
a[j+1]=a[j];
}
a[i+1]=m;
}
}
returnn+1;
}
voidsort(int*s,intn){
inti,j,k;
intmin,t;
for(i=0;imin=s[i];
k=i;
for(j=i+1;jif(s[j]min=s[j];
k=j;
}
}
if(k!
=i){
t=s[i];
s[i]=s[k];
s[k]=t;
}
}
}
main(){
inta[N],n;
intm;
n=input(a);
output(a,n);
sort(a,n);
output(a,n);
printf(“pleaseintputanumbertobeinsert\n”);
scanf(“%d”,&m);
n=insert(m,a,n);
output(a,n);
printf(“pleaseintputanumbertobeinsert\n”);
scanf(“%d”,&m);
n=insert(m,a,n);
output(a,n);
printf(“pleaseintputanumbertobeinsert\n”);
scanf(“%d”,&m);
n=insert(m,a,n);
output(a,n);
}
9.32
#include"stdio.h"
#defineN32
intchange(int,int*);
voidoutput(int*,int);
main(){
intn,a[N]={0},m;
printf(“Pleaseintputntochange:
\n”);
scanf(“%d”,&n);
m=change(n,a);
printf(“Thebinaryofn:
\n”);
output(a,m);
}
intchange(intn,int*a){
inti,cnt=0;
i=N-1;
while(n!
=0){
a[i]=n%2;
cnt++;
i--;
n=n/2;
}
returncnt;
}
voidoutput(int*a,intm){
inti;
for(i=N-m;iprintf(“%d”,a[i]);
printf(“\n”);
}
9.33
#include"stdio.h"
#include"stdlib.h"
#defineM15
voidinput(int*a){
inti=0,k;
while(i<15){
intd=rand()%20;
intflag=0;
for(k=0;k
if(a[k]==d){
flag=1;
break;
}
}
if(flag==1)continue;
a[i]=d;
i++;
}
}
main(){
inta[M];
inti;
input(a);
for(i=0;iprintf("%d\t",a[i]);
if((i+1)%5==0)
printf("\n");
}
}
9.34
#include"stdio.h"
#include"stdlib.h"
#defineM5
voidinput(inta[][M]){
inti,j;
for(i=0;ifor(j=0;ja[i][j]=rand()%50;
}
}
voidoutput(inta[][M]){
inti,j;
for(i=0;ifor(j=0;jprintf("%d\t",a[i][j]);
printf("\n");
}
}
main(){
inta[M][M];
inti,j;
intr[M]={0},c[M]={0},x=0,y=0;
input(a);
output(a);
for(i=0;ifor(j=0;j{
r[i]+=a[i][j];
c[j]+=a[i][j];
if(i==j)
x+=a[i][j];
if(i+j==M-1)
y+=a[i][j];
}
}
for(i=0;iprintf("row%d:
%d\n",i+1,r[i]);
for(j=0;jprintf("col%d:
%d\n",j+1,c[j]);
printf("x=%d\n",x);
printf("y=%d\n",y);
}
9.35
#include"stdio.h"
#include"stdlib.h"
#defineM5
#defineN6
voidinput(inta[][N]){
inti,j;
for(i=0;ifor(j=0;j/*scanf(“%d”,&a[i][j]);*/
a[i][j]=rand()%50;
}
}
voidoutput(int(*a)[N]){
inti,j;
for(i=0;ifor(j=0;jprintf("%d\t",a[i][j]);
printf("\n");
}
}
voidadd(inta[][N],int(*b)[N],intc[M][N]){
inti,j;
for(i=0;ifor(j=0;jc[i][j]=a[i][j]+b[i][j];
}
}
main(){
inta[M][N],b[M][N],c[M][N];
input(a);
input(b);
printf(“A:
\n”);
output(a);
printf(“B:
\n”);
output(b);
add(a,b,c);
printf(“A+B:
\n”);
output(c);
}
9.36
#include"stdio.h"
voidmain(){
inti,j;
printf(“%-30s”,“**AMUTIPLICATIONTABLE**\n”);
for(j=1;j<=9;j++)
printf(“\t(%d)”,j);
printf(“\n”);
printf(“……………………………….\n”);
for(i=1;i<=9;i++){
printf(“(%d)”,i);
for(j=1;j<=9;j++)
printf(“\t%d”,i*j);
printf(“\n”);
}
printf(“……………………………….\n”);
}
9.37
#include"stdio.h"
#include“stdlib.h”
#defineM5
#defineN4
voidinput(inta[][N]);
voidoutput(int(*a)[N]);
voidhandle(int(*a)[N],int*s);
voidmain(){
inta[M][N],s[M];
input(a);
printf(“Beforehandle:
\n”);
output(a);
handle(a,s);
printf(“afterhandle:
\n”);
output(a);
}
voidinput(inta[][N]){
inti,j;
for(i=0;ifor(j=0;ja[i][j]=rand()%100;
}
}
voidoutput(int(*a)[N]){
inti,j;
for(i=0;ifor(j=0;jprintf(“%d\t”,a[i][j]);
printf(“\n”);
}
}
voidhandle(int(*a)[N],int*s){
inti,j,max,t;
for(i=0;is[i]=0;
for(j=0;js[i]+=a[i][j];
}
max=0;
for(i=1;iif(s[i]>s[max])max=i;
}
for(j=0;jt=a[0][j];
a[0][j]=a[max][j];
a[max][j]=t;
}
}
9.38
#include"stdio.h"
#include"stdlib.h"
#defineN5
voidinput(inta[][N]);
voidoutput(int(*a)[N]);
voidinverse(int(*a)[N]);
voidmain(){
inta[N][N];
input(a);
printf("Beforehandle:
\n");
output(a);
inverse(a);
printf("afterhandle:
\n");
output(a);
}
voidinput(inta[][N]){
inti,j;
for(i=0;ifor(j=0;ja[i][j]=rand()%100;
}
}
voidoutput(int(*a)[N]){
inti,j;
for(i=0;ifor(j=0;jprintf("%d\t",a[i][j]);
printf("\n");
}
}
voidinverse(int(*a)[N]){
inti,j,t;
for(i=0;ifor(j=0;j
t=a[i][j];
a[i][j]=a[j][i];
a[j][i]=t;
}
}
}}