How to use Exponential and Logarithm In C++
The idea is to find the exponential of the given two numbers and print the logarithmic of the result.
printf("%g\n", log(exp(A) * exp(B)));
C++ Program to Add Two Numbers Using Exponential and Logarithm
C++
// C++ program to add two number // using log and exponential #include <bits/stdc++.h> using namespace std; // Function to return sum // of two number int addTwoNumber( int A, int B) { // Return sum of A and B return log ( exp (A) * exp (B)); } // Driver Code int main() { // Given two number int A = 4, B = 11; // Function call printf ( "sum = %d" , addTwoNumber(A, B)); return 0; } |
Output
sum = 15
- Time complexity: O(log n)
- Auxiliary Space: O(1)
Add Two Numbers in C++
The addition of two numbers is a simple task in C++ that can be done using the arithmetic addition operator (+). But there are many other ways to find the sum of two numbers in C++. In this article, we will discuss 7 different ways to add two numbers in C++.