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)
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;
}