I have programmed in C++, but I am interested in writing quantum programs. I have some experience with Microsoft's Q#, and I know about the canonical Shor's and Grover's algorithms.

Can anyone tell me how to write a quantum program to add two integers?

  • 2
    $\begingroup$ Hi and Welcome to QuantumComputing.SE. We prefer questions, where some effort has been done already. Please show us what you have already tried or searched for. $\endgroup$
    – luap42
    Sep 15, 2018 at 6:11
  • 1
  • 2
    $\begingroup$ The title for your question was "writing a program in Q#" but your question's body asks how to add two integers, so I've changed your title. Now you're at risk of having the article marked as a duplicate, because people have asked how to add 1+1 in Q# before. $\endgroup$ Sep 15, 2018 at 17:58

1 Answer 1


You will need quantum circuits called adders.

You have for example one from Cuccaro et al. and another from Himanshu et al.

  • $\begingroup$ Are these different from adders as implemented on a reversible classical computer? $\endgroup$
    – ahelwer
    Sep 17, 2018 at 23:32
  • $\begingroup$ I do not know how those are implemented on reversible classical computers (generally not considered) but it is possible that it was the inspiration. They adapt in quantum operations the addition bit-wise but trying to minimize the number of extra qubits and the complexity of the circuit. As the circuit is unitary, you can apply this with superposition. $\endgroup$
    – cnada
    Sep 18, 2018 at 0:18
  • $\begingroup$ There are also some links to adders in the Q# online documentation on docs.microsoft.com/en-us/quantum/quantum-formoreinfo. $\endgroup$ Sep 18, 2018 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.