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 ? 10 1704
Aravindh wrote On 03/02/06 13:04,: 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 ?
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********@gma il.com> writes: 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 ?
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 Cowan said: "Aravindh" <ar********@gma il.com> writes:
A 'C' program that takes two numbers and produces two other numbers. None of the four numbers must be similar.
<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.
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 "thirdpartyerro rmodule.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)
Aravindh wrote: A 'C' program that takes two numbers and produces two other numbers. None of the four numbers must be similar.
Could you define "similar"? Or is my non-native English failing me?
printf ("%d%d", & num1, & num2) ;
You either meant `scanf`, or you really have no clue...
if (num1 > num2) { num1 ++ ; num2 -- ; } else { num1 --; num2 ++ ; } printf ("%d%d\n", num1, num2) ;
Any better ideas ?
Define "better". Unless you mean "correct, compilable code"?
Heed other comments given elsethread as well.
--
BR, Vladimir
Marriage is not merely sharing the fettucine, but sharing the
burden of finding the fettucine restaurant in the first place.
-- Calvin Trillin
Richard Heathfield <in*****@invali d.invalid> writes: Micah Cowan said:
"Aravindh" <ar********@gma il.com> writes:
A 'C' program that takes two numbers and produces two other numbers. None of the four numbers must be similar. <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.
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 "thirdpartyerro rmodule.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 */ }
You've forgotten that you're now changing the inputs; you ought to
modify x and y instead... also, I'm assuming that last comment was
meant to be ... no longer == m ?
if (x == n)
{
x += 2; /* still != m, no longer == n, might be == y */
y += 2; /* still != n, no longer == m, no longer == x */
}
However, I don't think you need the second one, as the "might be == y"
s/b false. Because, x will only equal n if x != y modulo 2, which
means that also m != n modulo 2, and therefore adding 2 to x will
never let it be equal to y for the same reason that it's still not
equal to m.
I could be having a brain-fart, but ATM I think that's right.
Micah Cowan said: Richard Heathfield <in*****@invali d.invalid> writes:
You've forgotten that you're now changing the inputs; you ought to modify x and y instead...
Oops, oh yeah...
also, I'm assuming that last comment was meant to be ... no longer == m ?
Probably.
I could be having a brain-fart, but ATM I think that's right.
I find myself in 100% agreement with you. ;-)
(btw: wb, ltns, hand)
--
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)
Aravindh wrote: A 'C' program that takes two numbers and produces two other numbers. None of the four numbers must be similar.
Define similar.
--
Thad
Richard Heathfield <in*****@invali d.invalid> writes: (btw: wb, ltns, hand)
^^ ^^^^
Okay, I need these two explained to me: VERA doesn't have 'em...
:-)
On 2006-03-03, Micah Cowan <mi***@cowan.na me> wrote: Richard Heathfield <in*****@invali d.invalid> writes:
(btw: wb, ltns, hand) ^^ ^^^^
Okay, I need these two explained to me: VERA doesn't have 'em...
wb: welcome back.
ltns: long time no see.
:-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Patchwork |
last post by:
Hi Everyone,
Please take a look at the following (simple and fun) program:
////////////////////////////////////////////////////////////////////////////
/////////////
// Monster Munch, example program
#include <list>
|
by: francisco lopez |
last post by:
ok , first of all sorry if my english is not so good, I do my best.
here is my problem:
I don´t know much javascript so I wrote a very simple one to validate
a form I have on my webpage.
could you please have a look at the following script:
------------------------------------------------------------
|
by: 42 |
last post by:
I implemented a simple class inherited from Page to create a page
template. It simply wraps some trivial html around the inherited page,
and puts the inherited page into a form.
The problem I have run into is that the emitted html at the end of the
process is slightly different and doesn't work.
Please don't be put off by all the source code. All the guts are in this
first base class, and it doesn't do much. The rest is trivial...
|
by: Sender |
last post by:
Yesterday there was a very long thread on this query. (You can search on
this by post by 'sender' with subject 'Simple Problem' post date Oct 7 time
1:43p)
And in the end the following code was decided to open a new form:
---Code in the click event of a button: button1
if frm is nothing then
frm = new form2()
frm.show
|
by: one man army |
last post by:
Hi All-
I am new to PHP. I found FAQTS and the php manual. I am trying this
sequence, but getting 'no zip string found:'... PHP Version 4.4.0
$doc = new DomDocument;
$res = $doc->loadHTMLFile("./aBasicSearchResult.html");
if ( $res == true )
{
$zip = $doc->getElementById('zipRaw_id')->value;
if ( 0 != $zip ) {
| |
by: Vitali Gontsharuk |
last post by:
Hi!
I have a problem programming a simple client-server game, which is
called pingpong ;-)
The final program will first be started as a server (nr. 2) and then as
a client. The client then sends the message "Ping" to the server, which
reads it and answers with a "Pong".
The game is really simple and the coding should be also very simple! But
for me it isn't.
By the way, the program uses datagram sockets (UDP). And, I'm using
|
by: rdrink |
last post by:
I am just getting into pysqlite (with a fair amount of Python and MySQL
experience behind me) and have coded a simple test case to try to get
the hang of things...
yet have run into a 'stock simple' problem...
I can create a database 'test.db', add a table 'foo' (which BTW I
repeatedly DROP on each run) with one INTGER column 'id', and can
insert data into with:
cur.execute("INSERT INTO foo (id) VALUES (200)")
con.commit()
|
by: Chelong |
last post by:
hey,the follow is the text file content
========================================apple====pear==
one Lily 7 0 0 7 7
two Lily 20 20 6.6666 20 8
one Lily 0 10 2.85 4 0
two Lily 22 22 7.33326 2 5
two jenny 6 0 0 6 6
two jenny 12 0 0 12 12
three jenny 36 36 10.26 36 36
|
by: galiorenye |
last post by:
Hi,
Given this code:
A** ppA = new A*;
A *pA = NULL;
for(int i = 0; i < 10; ++i)
{
pA = ppA;
//do something with pA
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |