addition puzzle

Discussion in 'C++' started by robin, Sep 17, 2007.

  1. robin

    robin Guest

    write a c++ program to
    Add two integer numbers without using any arithmetic ,bitwise
    operator , printf,no loop no recursion nothing.
     
    robin, Sep 17, 2007
    #1
    1. Advertising

  2. robin

    Ian Collins Guest

    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.
     
    Ian Collins, Sep 17, 2007
    #2
    1. Advertising

  3. =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Sep 17, 2007
    #3
  4. > 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.
     
    Gernot Frisch, Sep 17, 2007
    #4
  5. "robin" <> wrote in message
    news:...
    > 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;
    }
     
    Bernd Jochims, Sep 18, 2007
    #5
  6. 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.
     
    Juha Nieminen, Sep 18, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Midnight Java Junkie

    Office Development (feature addition)

    Midnight Java Junkie, Jun 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    460
    Midnight Java Junkie
    Jun 20, 2004
  2. lezah
    Replies:
    7
    Views:
    770
    Mike Treseler
    Mar 2, 2004
  3. Julian

    Addition of one

    Julian, Oct 18, 2004, in forum: VHDL
    Replies:
    13
    Views:
    3,702
    rickman
    Oct 21, 2004
  4. Clemens Bosch

    Beginners questions for addition

    Clemens Bosch, Dec 2, 2004, in forum: VHDL
    Replies:
    0
    Views:
    561
    Clemens Bosch
    Dec 2, 2004
  5. Mark Dickinson

    Addition and multiplication puzzle

    Mark Dickinson, Oct 25, 2003, in forum: Python
    Replies:
    5
    Views:
    435
    Alex Martelli
    Oct 25, 2003
Loading...

Share This Page