addition puzzle

R

robin

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

Gernot Frisch

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.
 
B

Bernd Jochims

robin said:
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):eek:ne(l),two(r){}
}TWO;
std::vector<TWO> v;
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.one, t.v.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;
}
 
J

Juha Nieminen

robin said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top