电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

C语言程序设计慕课下编译答案

C语言程序设计慕课下编译答案_第1页
1/18
C语言程序设计慕课下编译答案_第2页
2/18
C语言程序设计慕课下编译答案_第3页
3/18
1 求最大公约数和最小公倍数(1 5 分) #include int fun1( int m, int n) //辗转相除法求m/n 的公约数 { int r; while (n) { r=m % n; m=n; n=r; } return m; } int fun2(int m,int n) //最小公倍数 { return m*n/fun1(m,n); } int main() { int a,b; scanf("%d,%d",&a,&b); //输入 printf("最大公约数:%d\n 最小公倍数:%d\n",fun1(a,b),fun2(a,b)); return 0; } 2排序并插入(1 5 分) #include void InsertionSort(int* arr, int n) // 插入排序 { int *last = 0, *next = 0, key = 0, i = 0; for (i = 1; i < n; ++i) { next = arr + i, key = *next; if (key < *arr) // 将待插的数据比第一个数据小,直接插到最前面。 { for (last = next; next != arr; next = last) *next = *--last; *arr = key; } else // 否则从后往前遍历,找到第一个小于关键字的位置插入。 { for (last = next; key < *--last; next = last) *next = *last; *next = key; } } } void OutPutArray(const int* arr, int n) // 打印一个数组 { int i; for (i = 0; i < n; ++i) { printf("%d", arr[i]); if(i

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

C语言程序设计慕课下编译答案

确认删除?
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群