⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch26-6.c

📁 C语言程序设计上机指导与练习 冶金工业出版社 刘怀亮
💻 C
字号:
#include<stdio.h> 
#include<conio.h> 
void main() 
{ 
   int i,j,k,a[6]={0},b[6]={0},c[11]={0},sub1(); 
   printf("\nplease input 5 int numbers to array1: "); 
   for(i=1;i<=5;i++) //a[0] for no use 
      scanf("%d",&a[i]); 
   getchar(); 
   sub1(a,5); 
   printf("\nplease input 5 int numbers to array2: "); 
   for(i=1;i<=5;i++) //b[0] for no use 
      scanf("%d",&b[i]); 
   getchar(); 
   sub1(b,5); 
   printf("\nthe sorted array a is:\n\n"); 
   for(i=1;i<=5;i++)
      printf("a[%d]=%d ",i,a[i]); 
   printf("\n"); 
   printf("\nthe sorted array b is:\n\n"); 
   for(i=1;i<=5;i++) 
      printf("b[%d]=%d ",i,b[i]); 
   k=i=j=1; 
   while(i<=5&&j<=5) 
      if(a[i]<b[j]) 
         c[k++]=a[i++]; //c[0] for no use 
      else 
         c[k++]=b[j++]; 
   if(i<j) /*appending the rest ones in array a*/ 
      for(;i<=5;i++) 
         c[k++]=a[i]; 
   else /*appending the rest ones in array b*/ 
      for(;j<=5;j++) 
         c[k++]=b[j]; 
   printf("\n\n"); 
   printf("\nthe merged array c is:\n\n"); 
   for(k=1;k<=10;k++) 
   { 
      if(k==6) 
         printf("\n"); 
      printf("c[%d]=%d ",k,c[k]); 
   } 
   while(!kbhit());
} 
int sub1(int b[],int n) 
{ 
   int t,i,j,post; 
   for(i=1;i<n;i++) 
   { 
      post=i; 
      for(j=i+1;j<=n;j++) 
          if(b[post]>b[j]) post=j; 
      if(post!=i) 
      { 
         t=b[i]; 
         b[i]=b[post]; 
         b[post]=t; 
      } 
   } 
   return 0; 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -