473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

addition puzzle

write a c++ program to
Add two integer numbers without using any arithmetic ,bitwise
operator , printf,no loop no recursion nothing.

Sep 17 '07 #1
5 1914
robin wrote:
write a c++ program to
Add two integer numbers without using any arithmetic ,bitwise
operator , printf,no loop no recursion nothing.
Why?

--
Ian Collins.
Sep 17 '07 #2
On 2007-09-17 10:38, robin wrote:
write a c++ program to
Add two integer numbers without using any arithmetic ,bitwise
operator , printf,no loop no recursion nothing.
How much do you pay?
http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

--
Erik Wikström
Sep 17 '07 #3
write a c++ program to
Add two integer numbers without using any arithmetic ,bitwise
operator , printf,no loop no recursion nothing.

Next puzzle:
Write to a newsgroup, asking to do your homework, and try to really
get a meaning ful answer.
Sep 17 '07 #4

"robin" <ro*******@gmail.comwrote in message
news:11**********************@n39g2000hsh.googlegr oups.com...
write a c++ program to
Add two integer numbers without using any arithmetic ,bitwise
operator , printf,no loop no recursion nothing.
// addit.cpp : Defines the entry point for the console application.
//
Non standard stuff - no arithmetic operators used. The function add also
sums the two ints.

#include "stdafx.h"
#include <ctime>
#include <iostream>
#include <vector>
#define ADD(c,x,y,s) XXX::XXX(c,x,y).print(s)
#ifndef T
#define T long
#endif
#ifndef AX
#define AX eax
#endif
#define SCR std::cout
using namespace std;
const size_t XLIMIT = 999;
class X
{
protected:
static T x;
X(){}
explicit X(const T& arg){x=arg;}
T const get() const{return x;}
};
class XXX :
private X{
static T b, a;
size_t index;
public:
explicit XXX(const size_t n, const T g, const T h):index(n)
{
a=g;
b=h;
f();
}
void print(ostream& os)
{os<<*this;}
private:
static void f()
{__asm{mov AX, a;
add AX, b;
mov x, AX}
}
friend ostream& operator <<(ostream& os, const XXX& ob)
{return os<<ob.index<<" "<<ob.a<<" + "<<ob.b<<" == "<<ob.get()<<'\n';}
};
T XXX::a;
T XXX::b;
T X::x;
typedef
struct Three{
typedef struct Two{
T one,
two;
Two(T l, T r):one(l),two(r){}
}TWO;
std::vector<TWOv;
Three()
{
for(int n=0; n<5000; n++)
v.push_back(TWO(rand()%XLIMIT,rand()%XLIMIT) );
}
}A;
typedef
struct Four{
Four(const A& t)
{
for(size_t i=0;i<t.v.size();i++)
{
ADD(i,t.v[i].one, t.v[i].two,SCR);
}
}
}B;

int add(int a, int b)
{
vector<int>x(a,0),y(b,0);
y.insert(y.end(),x.begin(),x.end());
return y.size();
}
int _tmain(int argc, _TCHAR* argv[])
{
srand(unsigned(time(0)));
A e;
B f(e);
int x =add(77777,77777);
cout<<x<<endl;
return 0;
}
Sep 17 '07 #5
robin wrote:
write a c++ program to
Add two integer numbers without using any arithmetic ,bitwise
operator , printf,no loop no recursion nothing.
Isn't that contradictory. If *nothing* can be used, then how can you
write something? A C++ program which uses *nothing* is an empty file.
Sep 18 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark Dickinson | last post by:
Can anyone either reproduce or explain the following apparently inconsistent behaviours of __add__ and __mul__? The class Gaussian provides a sub-bare-bones implementation of Gaussian integers (a...
1
by: xavier vazquez | last post by:
I have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of...
0
by: xavier vazquez | last post by:
have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of the...
5
by: ashish0799 | last post by:
HI I M ASHISH I WANT ALGORYTHMUS OF THIS PROBLEM Jigsaw puzzles. You would have solved many in your childhood and many people still like it in their old ages also. Now what you have got to do...
3
by: oncue01 | last post by:
Word Puzzle Task You are going to search M words in an N × N puzzle. The words may have been placed in one of the four directions as from (i) left to right (E), (ii) right to left (W), (iii) up...
6
by: Phoe6 | last post by:
Hi All, I would like to request a code and design review of one of my program. n-puzzle.py http://sarovar.org/snippet/detail.php?type=snippet&id=83 Its a N-puzzle problem solver ( Wikipedia page...
1
by: Braulio | last post by:
Helo! I'm Having A Big Time Trying To Solve This Puzzle, Hope Somebody Could Help Me: I Need To Be Able To Make An Addition Of Hours And Minutes, But When I Try To Add 20:50 Plus 10:45, I Don't...
2
by: Gio | last post by:
I'm getting K&R (it's on the way), should I also get the Answer Book? And while I'm there, should I get the Puzzle Book? Or should I save the Puzzle Book for when I'm more advanced? - Gio ...
4
by: honey777 | last post by:
Problem: 15 Puzzle This is a common puzzle with a 4x4 playing space with 15 tiles, numbered 1 through 15. One "spot" is always left blank. Here is an example of the puzzle: The goal is to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.