Jump to content

Write a small program adding two positive numbers with out using + or -*-


Recommended Posts

Posted
19 minutes ago, Maryadaramanna said:

This is wrong. It holds true only when a isn’t equal to b.
you’re limiting the value of the function.

Yup...you have good point....

let me try with different alternative....

Posted
6 hours ago, dasari4kntr said:

This is one alternate way i can think....

a+b= (a2-b2)/(a-b)

FGMYZ1uOZWsX7lEOyk9dwcffbf4unEvopc_p-RgJ

Mukku eshi ante direct ga supiyakunda head back gunda hand thippi mukku supettinattu vundhi uncle

  • Haha 1
Posted
6 hours ago, dasari4kntr said:

This is one alternate way i can think....

a+b= (a2-b2)/(a-b)

FGMYZ1uOZWsX7lEOyk9dwcffbf4unEvopc_p-RgJ

+ vaadodhu ani nuvvu vaadesinaav kadheti

Posted

def add(x, y):
    while x:
        x, y = ((x & y) << 1), (x ^ y)
    return y

XOR operation with carry bit

Posted
4 minutes ago, redsox said:

def add(x, y):
    while x:
        x, y = ((x & y) << 1), (x ^ y)
    return y

XOR operation with carry bit

Functions use cheyakunda possible aa

Posted
7 hours ago, Sucker said:

Yendi vuncle Satday lu Funday lu kuda ila ee coding lu. Poragallani kuda intla ila ne saavaodthurra yendi. 

Nuvvu rayi chudham

Posted
Just now, Hydrockers said:

Functions use cheyakunda possible aa

I mean, functions make it simpler kada. What's the point of not using a function? 🤨 you input two integers and return the sum value 

Posted
7 hours ago, Sucker said:

Yendi vuncle Satday lu Funday lu kuda ila ee coding lu. Poragallani kuda intla ila ne saavaodthurra yendi. 

Nee lanti freeloader gallani ye bongu radu ga 😂😂😂

Posted
1 minute ago, redsox said:

I mean, functions make it simpler kada. What's the point of not using a function? 🤨 you input two integers and return the sum value 

Functions use chesina direct + use chesina same ga ?

Run time differ avvuda ? Memory differ untada? #justasking forgoted all the programming skills a decade back 

Posted
16 minutes ago, Hydrockers said:

Functions use chesina direct + use chesina same ga ?

Run time differ avvuda ? Memory differ untada? #justasking forgoted all the programming skills a decade back 

Functions add additional overhead since you have to allocate additional memory and stack space. For a simple function like this, the additional overhead is pretty much negligible. The important use of a function is it's reusablility. Even if it adds additional overhead it's preferred. 

Ok, I misinterpreted your question. If you're asking about direct addition with a '+' vs this function, the answer is bitwise operations are FAST. Using a '+' sign takes more clock cycles than a bitwise operation.

 

Posted
2 minutes ago, redsox said:

Functions add additional overhead since you have to allocate additional memory and stack space. For a simple function like this, the additional overhead is pretty much negligible. The important use of a function is it's reusablility. Even if it adds additional overhead it's preferred. 

You can still put the same logic without a function (like below) and still get the result  

while x:
        x, y = ((x & y) << 1), (x ^ y)
print (y) # no return statement as it's not in a function

 

C language aa kaka ?

Posted
Just now, Hydrockers said:

C language aa kaka ?

kadu Python

C aithe int x, y; ani mundu variables declare cheyali. Plus the operators are a little bit different

Posted
1 hour ago, Hydrockers said:

Nuvvu rayi chudham

Yooo vuncle. Nenu program raasthe Oscar award kuda vasthadi. 

Posted
1 hour ago, Tdpabhimaani said:

Nee lanti freeloader gallani ye bongu radu ga 😂😂😂

Oho ee ID la thiruguthunnava. Nice ra. Carry on ra nee yedupu.

Posted
1 hour ago, Sucker said:

Oho ee ID la thiruguthunnava. Nice ra. Carry on ra nee yedupu.

Who is he ?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...