未完作业剪切本.docVIP

  • 3
  • 0
  • 约1.12万字
  • 约 27页
  • 2018-01-01 发布于河南
  • 举报
未完作业剪切本

未完作业剪切本 标准冒泡法 #includestdio.h void main() { int a,b,c,d,t=0; printf(输入四个数,每个数之间用空格隔开,输完最后一个数后回车:\n); scanf(%d%d%d%d,a,b,c,d); if(ab) { t=a; a=b; b=t; } if(ac) { t=a; a=c; c=t; } if(ad) { t=a; a=d; d=t; } if(bc) { t=b; b=c; c=t; } if(bd) { t=b; b=d; d=t; } if(cd) { t=c; c=d; d=t; } printf(%d%d%d%d\n,a,b,c,d); } 比较五个名字的首字母大小并输出 #includestdio.h #includestring.h void main() { int i,k,i2; char wds[5][10],a[10]; for(i=0;i5;i++)//循环输入的数不多于五个// { printf(请输入%d个名字:,i+1); gets(wds[i]); } for(i2=0;i210;i2++) { for(i=0;i4;i++)//i的值比大小后面只有四位数比较 if(wds[i][0]wds[i+1][0])//比较后一个数和前一个数的大小// { strcpy(a,wds[i]); strcpy(wds[i],wds[i+1]);//冒泡计算替值 strcpy(wds[i+1],a); }} for(k=0;k5;k++) { puts(wds[k]);//k为循环的数组不是循环输出结果;// } } 三数排序 #includestdio.h #includeiostream.h void main() { int a,b,c; cout请输入三个整型数:endl; cinabc; void sort(int m,int n,int o) { cout经过排序后的输出为:(m=n?m:n)o?(mn?m:n):oendl; } sort(a,b,c); } 十个数排序 #includestdio.h #includeiostream.h void main() { int a[11]; int i,j,k; printf(intput 10 numbers:\n); for(i=1;i11;i++) scanf(%d,a[i]); printf(\n); for(i=1;i=9;i++) for(j=1;j=10-i;j++) if(a[j]a[j+1]) { k=a[j];a[j]=a[j+1];a[j+1]=k; } printf(the sorted numbers:\n); for(i=1;i11;i++) printf(%d ,a[i]); } 函数名: rename 功 能: 重命名文件 用 法: int rename(char *oldname, char *newname); 程序例: #include stdio.h int main(void) { char oldname[80], newname[80]; /* prompt for file to rename and new name */ printf(File to rename: ); gets(oldname); printf(New name: ); gets(newname); /* Rename the file */ if (rename(oldname, newname) == 0) printf(Renamed %s to %s.\n, oldname, newname); else perror(rename); return 0; } #include stdio.h #include time.h int main(void) { time_t t; time(t); printf(Todays date and time: %s\n, ctime(t)); re

文档评论(0)

1亿VIP精品文档

相关文档