请帮忙看看c语言编的程序,谢谢
题目:输入两个正整数m和n,求其最大公约数和最小公倍数。程序如下:#include<stdio.h>main(){longintnum1,num2,m,n,i,arg;a...
题目:输入两个正整数m和n,求其最大公约数和最小公倍数。
程序如下:
#include<stdio.h>
main()
{long int num1,num2,m,n,i,arg;
arg=1;
printf("please input two numbers:%d");
scadf("%d,%d\n",&num1,&num2);
m=num1;
n=num2;
for(i=2;i<=m&&i<=n;i++) \\对i赋值,执行循环
{if(m%i==0&&n%i==0) \\如果m和n同时能被i整除
{m=m/i;
n=n/i;
arg*=i; 把约数的积送入arg中
}
}
printf("zuidagongyueshuwei:%d:",arg);
for(i=m;i>=m&&i>=n;i++) \\i的初值,赋m,n效果应该是一样的
{if(i%m==0&&i%n==o)
break;
}
printf("zuixiaogongbeishuwei:%d:",i);
}
上面的程序我也不知道正确与否,是我自己编的,请各位帮忙给看看对不对 展开
程序如下:
#include<stdio.h>
main()
{long int num1,num2,m,n,i,arg;
arg=1;
printf("please input two numbers:%d");
scadf("%d,%d\n",&num1,&num2);
m=num1;
n=num2;
for(i=2;i<=m&&i<=n;i++) \\对i赋值,执行循环
{if(m%i==0&&n%i==0) \\如果m和n同时能被i整除
{m=m/i;
n=n/i;
arg*=i; 把约数的积送入arg中
}
}
printf("zuidagongyueshuwei:%d:",arg);
for(i=m;i>=m&&i>=n;i++) \\i的初值,赋m,n效果应该是一样的
{if(i%m==0&&i%n==o)
break;
}
printf("zuixiaogongbeishuwei:%d:",i);
}
上面的程序我也不知道正确与否,是我自己编的,请各位帮忙给看看对不对 展开
6个回答
展开全部
Compiling...
shiyan.c
C:\Documents and Settings\user\shiyan.c(6) : warning C4013: 'scadf' undefined; assuming extern returning int
C:\Documents and Settings\user\shiyan.c(9) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(9) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb6'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd4'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb8'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb3'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd6'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xa3'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xac'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd6'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb4'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd0'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd0'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd1'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xad'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xbb'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb7'
C:\Documents and Settings\user\shiyan.c(10) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\user\shiyan.c(10) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(10) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xc8'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xe7'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xb9'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xfb'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xba'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xcd'
C:\Documents and Settings\user\shiyan.c(10) : error C2146: syntax error : missing ';' before identifier 'n'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xcd'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xac'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xca'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xb1'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xc4'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xdc'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xb1'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xbb'
C:\Documents and Settings\user\shiyan.c(10) : error C2146: syntax error : missing ';' before identifier 'i'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xd5'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xfb'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xb3'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xfd'
C:\Documents and Settings\user\shiyan.c(11) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xb0'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xd1'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xd4'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xbc'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xca'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xfd'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xc4'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xbb'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xfd'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xcb'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xcd'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xc8'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xeb'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xd6'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xd0'
C:\Documents and Settings\user\shiyan.c(14) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\user\shiyan.c(17) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(17) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xc4'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb3'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xf5'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd6'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb8'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb3'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd0'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xa7'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb9'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xfb'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd3'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xa6'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb8'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xc3'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xca'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xc7'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd2'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xbb'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd1'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xf9'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xc4'
C:\Documents and Settings\user\shiyan.c(18) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\user\shiyan.c(18) : error C2065: 'o' : undeclared identifier
C:\Documents and Settings\user\shiyan.c(19) : error C2043: illegal break
Error executing cl.exe.
shiyan.exe - 88 error(s), 1 warning(s)
在vc++编译结果
建议你找现成的算法看看.
你的算法好象有问题.
不过自己动手的好习惯很好.
加油吧
shiyan.c
C:\Documents and Settings\user\shiyan.c(6) : warning C4013: 'scadf' undefined; assuming extern returning int
C:\Documents and Settings\user\shiyan.c(9) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(9) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb6'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd4'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb8'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb3'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd6'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xa3'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xac'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd6'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb4'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd0'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd0'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xd1'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xad'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xbb'
C:\Documents and Settings\user\shiyan.c(9) : error C2018: unknown character '0xb7'
C:\Documents and Settings\user\shiyan.c(10) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\user\shiyan.c(10) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(10) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xc8'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xe7'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xb9'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xfb'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xba'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xcd'
C:\Documents and Settings\user\shiyan.c(10) : error C2146: syntax error : missing ';' before identifier 'n'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xcd'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xac'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xca'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xb1'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xc4'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xdc'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xb1'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xbb'
C:\Documents and Settings\user\shiyan.c(10) : error C2146: syntax error : missing ';' before identifier 'i'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xd5'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xfb'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xb3'
C:\Documents and Settings\user\shiyan.c(10) : error C2018: unknown character '0xfd'
C:\Documents and Settings\user\shiyan.c(11) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xb0'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xd1'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xd4'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xbc'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xca'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xfd'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xc4'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xbb'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xfd'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xcb'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xcd'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xc8'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xeb'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xd6'
C:\Documents and Settings\user\shiyan.c(13) : error C2018: unknown character '0xd0'
C:\Documents and Settings\user\shiyan.c(14) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\user\shiyan.c(17) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(17) : error C2017: illegal escape sequence
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xc4'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb3'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xf5'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd6'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb8'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb3'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd0'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xa7'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb9'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xfb'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd3'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xa6'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb8'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xc3'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xca'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xc7'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd2'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xbb'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xd1'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xf9'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xb5'
C:\Documents and Settings\user\shiyan.c(17) : error C2018: unknown character '0xc4'
C:\Documents and Settings\user\shiyan.c(18) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\user\shiyan.c(18) : error C2065: 'o' : undeclared identifier
C:\Documents and Settings\user\shiyan.c(19) : error C2043: illegal break
Error executing cl.exe.
shiyan.exe - 88 error(s), 1 warning(s)
在vc++编译结果
建议你找现成的算法看看.
你的算法好象有问题.
不过自己动手的好习惯很好.
加油吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
main()
{long int num1,num2,m,n,i,arg;
arg=1;
printf("please input two numbers:");
scanf("%d",&num1);
fflush(stdin); //忽略了回车,否则把回车当成输入了
scanf("%d",&num2);
m=num1;
n=num2;
for(i=2;i<=m && i<=n;i++) //对i赋值,执行循环
{if(m%i==0&&n%i==0) //如果m和n同时能被i整除
{m=m/i;
n=n/i;
arg*=i; //把约数的积送入arg中
}
}
printf("zuidagongyueshuwei:%d:",arg);
printf("zuixiaogongbeishuwei:%d:",num1*num2/arg); //最大公约数乘以最小公倍数为两数的乘积
}
main()
{long int num1,num2,m,n,i,arg;
arg=1;
printf("please input two numbers:");
scanf("%d",&num1);
fflush(stdin); //忽略了回车,否则把回车当成输入了
scanf("%d",&num2);
m=num1;
n=num2;
for(i=2;i<=m && i<=n;i++) //对i赋值,执行循环
{if(m%i==0&&n%i==0) //如果m和n同时能被i整除
{m=m/i;
n=n/i;
arg*=i; //把约数的积送入arg中
}
}
printf("zuidagongyueshuwei:%d:",arg);
printf("zuixiaogongbeishuwei:%d:",num1*num2/arg); //最大公约数乘以最小公倍数为两数的乘积
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
scanf, 应该不是 scand...
其他。。。
太长,不想看了。。。
哈哈。。。
其他。。。
太长,不想看了。。。
哈哈。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
C很重要呀~好好学习呀~由于你的思路不知道正确不~好长~呵呵,就不看啦~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有很多错的地方。在有:注释要/* */
多看点书吧,
嗯 是不会在给我留言,
多看点书吧,
嗯 是不会在给我留言,
参考资料: 最好把你提问的网址给我,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询