云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > c语言习题及答案 - 爱课程mooc

c语言习题及答案 - 爱课程mooc

  • 62 次阅读
  • 3 次下载
  • 2025/5/2 3:32:35

输出每行的开头数字: \ 输出第m行n列中的值:\ 输入样例: 输出样例:

#include #include int i,j; int main() {

for(i=0; i<10; i++) printf(\ putchar('\\n'); for (i=0; i<10; i++) {

printf(\ for (j=0; j<10; j++)

printf(\ printf(\

}

return 0; }

12.4

最大公约数(4分)

题目内容:

按照如下函数原型编写子函数计算正整数a和b的所有公约数。第一次调用,返回最大公约数。以后只要再使用相同参数调用,每次返回下一个小一些的公约数。无公约数时,函数CommonFactors()返回-1,主函数中不输出任何信息。 函数原型: int CommonFactors(int a, int b) 程序运行结果示例1: Input a and b: 100,50↙

Common factor 1 is 50 Common factor 2 is 25 Common factor 3 is 10 Common factor 4 is 5 Common factor 5 is 2 Common factor 6 is 1

程序运行结果示例2: Input a and b: 7,-3↙

输入格式: \ 输出格式:

输出公约数: \ 输入提示信息:\ 输入样例: 输出样例:

#include

int MaxCommonFactor(int a,int b); int CommonFactors(int a, int b); int main() {

int a,b;

printf(\ scanf(\ if (a>0 &&b>0)

CommonFactors(a, b); return 0; }

int CommonFactors(int a, int b) {

int *gcd=(int *)malloc(sizeof(int)*512); int i;

int index = 1;

b = MaxCommonFactor(a, b); for(i=b; i>0; i--)

if((a%i == 0) && (b%i == 0)) gcd[index++] = i; gcd[0] = index;

for (i=1; i

printf(\ return gcd; }

int MaxCommonFactor(int a,int b) {

int temp;

if(a<=0||b<=0) return -1; while(b!=0) {

temp=a%b; a=b; b=temp; }

return a; }

搜索更多关于: c语言习题及答案 - 爱课程mooc 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

输出每行的开头数字: \ 输出第m行n列中的值:\ 输入样例: 输出样例: #include #include int i,j; int main() { for(i=0; i<10; i++) printf(\ putchar('\\n'); for (i=0; i<10; i++) { printf(\ for (j=0; j<10; j++) printf(\ printf(\ } return 0; } 12.4 最大公约数(4分) 题目内容: 按照如下函数

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com