一个简单的'C'问题 [英] A simple 'C' problem
问题描述
一个C程序,需要两个数字并产生另外两个数字。
四个数字中的任何一个都不能相似。
printf ("%d%d"& num1,& num2);
if(num1> num2){
num1 ++; num2 - ;
}
else {
num1 - ; num2 ++;
}
printf("%d%d \ n",num1,num2);
任何更好的想法?
A ''C'' program that takes two numbers and produces two other numbers.
None of the four numbers must be similar.
printf ("%d%d", & num1, & num2) ;
if (num1 > num2) {
num1 ++ ; num2 -- ;
}
else {
num1 --; num2 ++ ;
}
printf ("%d%d\n", num1, num2) ;
Any better ideas ?
推荐答案
Aravindh写于03/02/06 13:04,:
Aravindh wrote On 03/02/06 13:04,:
一个C程序,它接受两个数字并产生另外两个数字。
四个数字中没有一个必须相似。
> printf("%d%d",& num1,& num2);
if(num1> num2){
num1 ++; num2 - ;
}
其他{
num1 - ; num2 ++;
}
printf("%d%d \ n",num1,num2);
任何更好的想法?
A ''C'' program that takes two numbers and produces two other numbers.
None of the four numbers must be similar.
printf ("%d%d", & num1, & num2) ;
if (num1 > num2) {
num1 ++ ; num2 -- ;
}
else {
num1 --; num2 ++ ;
}
printf ("%d%d\n", num1, num2) ;
Any better ideas ?
>
几乎任何想法都会更好。 Jellybean pizza
会更好。
(如果你想要一个关于某项计划的建议,请发布一个
计划和不是一两个随机选择的外行代码 - 即使在你提供的小b
中,我可以看到两个保证错误;谁知道如何很多
整个程序是否持有?)
-
Er ********* @sun.com
Almost any idea would be better. "Jellybean pizza"
would be better.
(If you want suggestions about a program, post a
program and not a couple randomly-chosen lines of out-
of-context code. Even in the little you''ve provided
I can see two guaranteed mistakes; who knows how many
the complete program holds?)
--
Er*********@sun.com
" Aravindh" < AR ******** @ gmail.com>写道:
"Aravindh" <ar********@gmail.com> writes:
一个C程序,它接受两个数字并产生另外两个数字。
四个数字中的任何一个都不能相似。
printf("%d%d",& num1,& num2);
if(num1> num2){
num1 ++; num2 - ;
}
其他{
num1 - ; num2 ++;
}
printf("%d%d \ n",num1,num2);
任何更好的想法?
A ''C'' program that takes two numbers and produces two other numbers.
None of the four numbers must be similar.
printf ("%d%d", & num1, & num2) ;
if (num1 > num2) {
num1 ++ ; num2 -- ;
}
else {
num1 --; num2 ++ ;
}
printf ("%d%d\n", num1, num2) ;
Any better ideas ?
>
以上代码不可编译。请发布完整的示例。
我认为您打算使用scanf()而不是printf()作为第一个
。
你的州问题非常*模糊......解决方案是无限的。你
甚至可以忽略输入数字并产生rand()
或其他东西的结果。
The above code is not compileable. Please post complete examples.
I think you meant to use scanf() rather than printf() for the first
one.
Your state problem is *very* vague... the solutions are infinite. You
could even ignore the input numbers and produce the results of rand()
or something.
Micah考恩说:
Micah Cowan said:
" Aravindh" < AR ******** @ gmail.com>写道:
"Aravindh" <ar********@gmail.com> writes:
一个C程序,它接受两个数字并产生另外两个数字。
四个数字中的任何一个都不能相似。
A ''C'' program that takes two numbers and produces two other numbers.
None of the four numbers must be similar.
< snip>
你的州问题非常*模糊......解决方案是无限的。你甚至可以忽略输入数字并产生rand()
或其他东西的结果。
<snip>
Your state problem is *very* vague... the solutions are infinite. You
could even ignore the input numbers and produce the results of rand()
or something.
不,他不能(如果我对问题的理解是正确的),如果
结果rand()产生两个输入
数字中的一个或其他(或者两个)。
这应该这样做:
#include< stdio.h>
#include< limits。 h>
#include" thirdpartyerrormodule.h"
void silly(unsigned int m,unsigned int n)
{
unsigned int x = UINT_MAX - m;
unsigned int y = UINT_MAX - n;
if(m == n){error( 输入错误 - 数字是重复的;); }
/ * x绝对不同于m(UINT_MAX是奇数)* /
/ * y绝对不同于n(UINT_MAX是奇数)* /
/ * m绝对不同于n(已经检查过)* /
/ * x肯定与y不同(因为m!= n)* /
/ * m可能等于y,在这种情况下x将等于n * /
if(m == y)
{
m + = 2; / *仍然!= x,不再是== y,可能是== n * /
n + = 2; / *仍然!= y,不再== x,不再== n * /
}
printf("%u%u% u%u \ n",m,n,x,y);
}
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
No, he can''t (if my understanding of the problem is correct), in case the
result of rand() produces one or other (or even both) of the two input
numbers.
This should do it:
#include <stdio.h>
#include <limits.h>
#include "thirdpartyerrormodule.h"
void silly(unsigned int m, unsigned int n)
{
unsigned int x = UINT_MAX - m;
unsigned int y = UINT_MAX - n;
if(m == n) { error("input error - numbers are duplicates"); }
/* x is definitely different from m (UINT_MAX is odd) */
/* y is definitely different from n (UINT_MAX is odd) */
/* m is definitely different from n (checked already) */
/* x is definitely different from y (because m != n) */
/* m might equal y, in which case x will equal n */
if(m == y)
{
m += 2; /* still != x, no longer == y, might be == n */
n += 2; /* still != y, no longer == x, no longer == n */
}
printf("%u %u %u %u\n", m, n, x, y);
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
这篇关于一个简单的'C'问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!