求助c程,呼唤大神。

楼主

lyco22 [离线]

6VIP

发帖数:298 积分:3426
1楼

有哪位做过求最小公倍数和最大公约数的题目?如何在现有变量下完成两个数的求值呢?题目稍后上。


发表于 2012/4/17 8:44:33

色拉 [离线]

6VIP

发帖数:169 积分:3282
2楼

程序填空,不要改变与输入输出有关的语句。
输入一个正整数 repeat (0<repeat<10),做 repeat 次下列运算:
输入两个正整数m和n,输出它们的最小公倍数和最大公约数。
输入输出示例:括号内为说明
输入:
3 (repeat=3)
3 7 (m=3,n=7)
24 4 (m=24,n=4)
24 18 (m=24,n=18)
输出:
21 is the least common multiple of 3 and 7, 1 is the greatest common divisor of 3 and 7.
24 is the least common multiple of 24 and 4, 4 is the greatest common divisor of 24 and 4.
72 is the least common multiple of 24 and 18, 6 is the greatest common divisor of 24 and 18.




#include <stdio.h>
int main(void)
{
int ***, lcm, m, n;
int repeat, ri;

scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%d", &m);
scanf("%d", &n);
if(m <= 0 &#124;&#124; n <= 0)
printf("m <= 0 or n <= 0");
else{
/*---------*/
printf("%d is the least common multiple of %d and %d, %d is the greatest common divisor of %d and %d.\n", lcm, m, n, ***, m, n);
}
}
}



      
发表于 2012/4/17 11:54:19

hooh830906 [离线]

6VIP

发帖数:379 积分:3214
3楼

***。。。这是变成违禁字符了?

      
发表于 2012/4/17 12:31:44

hooh830906 [离线]

6VIP

发帖数:379 积分:3214
4楼

违禁词喜感,ccp

      
发表于 2012/4/17 14:42:47

yushuang [离线]

6VIP

发帖数:201 积分:2992
5楼

#include <stdio.h>
int main(void)
{
int ***, lcm, m, n;
int repeat, ri,i; scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%d", &m);
scanf("%d", &n);
if(m <= 0 &#124;&#124; n <= 0)
printf("m <= 0 or n <= 0");
else{
lcm=m*n;
for(i=1;i<=lcm;i++)
if(i%m==0&&i%n==0){
lcm=i;
break;
}
if(m<n)
***=m;
else
***=n;
for(i=***;i>=1;i++)
if(m%i==0&&n%i==0){
***=i;
break;
}
printf("%d is the least common multiple of %d and %d, %d is the greatest common divisor of %d and %d.\n", lcm, m, n, ***, m, n);
}
}

      
签名档

[URL=http://www.insect-paradise.com][img]http://obbs.net/home/upload/forum/2004052811222633.gif[/img][/URL]

发表于 2012/4/17 17:39:11

无语 [离线]

6VIP

发帖数:328 积分:3514
6楼

违禁词喜感,ccp

      
发表于 2012/4/17 18:35:35

云游四海 [离线]

6VIP

发帖数:163 积分:3560
7楼

违禁词。。。哈哈~~~

      
签名档

渴望一片天地,那里有我!

发表于 2012/4/17 20:20:27

Ling [离线]

6VIP

发帖数:57 积分:3093
8楼

Our Party g*d




      
发表于 2012/4/17 21:51:46

sady [离线]

6VIP

发帖数:120 积分:3092
9楼

原本没有i这个变量的...
我想说在不添加变量的前提下,能否做出?



      
发表于 2012/4/18 0:01:22

MF_max [离线]

6VIP

发帖数:489 积分:3400
10楼

额。。。这个,我看看袄。。。好久前做的,我直接复制上来的,都不知道有木有错

      
签名档

试要想过,考前要拜佛。。。

发表于 2012/4/18 2:02:21
返回本版
1
2
3

请您先 登录 再进行发帖

快速回复楼主