 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write you own Power without using multiplication(*) and division(/) operators in C Program
Power function is calculated using the times multiple i.e. 5n is 5*5*5… n times. For this function, to work properly without using multiplication(*) and division(/) operators we will use nested loops that add the numbers n number of time.
Example
#include <iostream> using namespace std; int main() {    int a= 4 , b = 2;    if (b == 0)       cout<<"The answer is"<<1;    int answer = a;    int increment = a;    int i, j;    for(i = 1; i < b; i++) {       for(j = 1; j < a; j++) {          answer += increment;       }       increment = answer;    }    cout<<"The answer is "<<answer;    return 0; }  Output
The answer is 16
Advertisements
 