您好,欢迎访问三七文档
15990621陈志刚物联网专业第一题:#includestdio.hvoidmain(){intx,i,a[11]={2,4,6,8,10,12,14,16,18,20};printf(请输入要插入的数值x:\n);scanf(%d,&x);for(i=9;i=0;i--){if(x=a[i]){a[i+1]=a[i];if(i==0)a[i]=x;}else{a[i+1]=x;break;}}for(i=0;i11;i++)printf(%3d,a[i]);printf(\n);}第二题:升序:#includestdio.h#defineN7voidmain(){inti,j,k,t;inta[N]={13,7,24,9,2,17,22};printf(排序前:);for(i=0;iN;i++)printf(%5d\t,a[i]);printf(\n);for(i=0;iN-1;i++){k=i;for(j=i+1;jN;j++)if(a[j]a[k])k=j;if(i!=k){t=a[i];a[i]=a[k];a[k]=t;}}printf(排序后:);for(i=0;iN;i++)printf(%5d\t,a[i]);printf(\n);}降序:#includestdio.h#defineN7voidmain(){inti,j,k,t;inta[N]={13,7,24,9,2,17,22};printf(排序前:);for(i=0;iN;i++)printf(%5d\t,a[i]);printf(\n);for(i=0;iN-1;i++){k=i;for(j=i+1;jN;j++)if(a[j]a[k])k=j;if(i!=k){t=a[i];a[i]=a[k];a[k]=t;}}printf(排序后:);for(i=0;iN;i++)printf(%5d\t,a[i]);printf(\n);}第三题:升序:#includestdio.h#defineN7voidmain(){inti,j,t;inta[N]={13,7,24,9,2,17,22};printf(排序前:);for(i=0;iN;i++)printf(%5d\t,a[i]);printf(\n);for(i=0;iN-1;i++)for(j=0;jN-i-1;j++){if(a[j]a[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}}printf(排序后:);for(i=0;iN;i++)printf(%5d\t,a[i]);printf(\n);}降序:#includestdio.h#defineN7voidmain(){inti,j,t;inta[N]={13,7,24,9,2,17,22};printf(排序前:);for(i=0;iN;i++)printf(%5d\t,a[i]);printf(\n);for(i=0;iN-1;i++)for(j=0;jN-i-1;j++){if(a[j]a[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}}printf(排序后:);for(i=0;iN;i++)printf(%5d\t,a[i]);printf(\n);}
本文标题:c语言知识点
链接地址:https://www.777doc.com/doc-2908078 .html