您的当前位置:首页正文

c语言第7章实验报告

2023-07-22 来源:易榕旅网
 数组

7.1

#include

void main() {int i,j,n,a[101]; for(i=1;i<=100;i++) a[i]=i;

for(i=2;iif(a[j]%a[i]==0) a[j]=0;

} printf(\"\\n\");

for(i=2,n=0;i<=100;i++) {if(a[i]!=0)

{printf(\"%5d\ n++;

} if(n==10) {printf(\"\\n\");

n=0;

}

} }

7.2题

#include void main()

{int i,j,min,temp,a[11]; printf(\"Enter data:\\n\"); for(i=1;i<=10;i++) {printf(\"a[%d]=:\ scanf(\"%d\ } printf(\"\\n\"); for(i=1;i<=10;i++) printf(\"%5d\ printf(\"\\n\"); for(i=1;i<=9;i++)

{min=i;

for(j=i+1;j<=10;j++) if(a[min]>a[j]) min=j; temp=a[i]; a[i]=a[min]; a[min]=temp; }

printf(\"\\n The sorted numbers:\\n\"); for(i=1;i<=10;i++) printf(\"%5d\ }

7.6题 #define N 11 void main() {int i,j,a[N][N];

for(i=1;ifor(i=3;iprintf(\"\\n\"); }

7.9题

#include #define N 15 void main()

{int i=1,j,number,top,bott,mid,loca,a[N],flag=1,sign=0; char c;

printf(\"Enter data:\\n\"); scanf(\"%d\ while(i{scanf(\"%d\ if(a[i]>=a[i-1]) i++; else

printf(\"Enter this data again:\"); } printf(\"\\n\"); for(i=0;i{printf(\"Imput number to look for:\"); scanf(\"%d\ loca=0;

top=0; bott=N-1;

if((numbera[N-1]))

loca=-1;

/*else*/

while((! sign)&&(top<=bott))

{mid=(bott+top)/2; if(number==a[mid]) {loca=mid;

printf(\"Find %d,its position is %d \\n\ sign=1; }

else if (numberbott=mid-1;

else }

top=mid+1;

else if (sign==1||loca==-1)

printf(\"%d is not found.\\n\} }

7.12题

#include void main() {int j,n;

char ch[80],tran[80]; printf(\"\\nInput cipher code:\"); gets(ch);

printf(\"\\n\\ncipher code:%s\ j=0;

while(ch[j]!='\\0')

{if((ch[j] >='A')&&(ch[j]<='Z'))

tran[j]=155-ch[j];

else if ((ch[j] >='a')&&(ch[j]<='z'))

tran[j]=219-ch[j];

else

tran[j]=ch[j];

j++; } n=j;

printf(\"\\noriginal text:\"); for(j=0;j7.15题

#include void main() {char s1[80],s2[80]; int i;

printf(\"Input s2:\"); scanf(\"%s\

for(i=0;i<=strlen(s2);i++) s1[i]=s2[i]; printf(\"s1: %s\\n\}

因篇幅问题不能全部显示,请点此查看更多更全内容