Created
April 8, 2017 16:33
-
-
Save ramachandrajr/42be36d88ba23863b5512d07c3c68b08 to your computer and use it in GitHub Desktop.
Cpp Discussions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You cannot do << to the cin, you can do 'cin >> auto a' though but I | |
// think it'd be great to initialize int's first and then getting values. | |
cin<< auto a; | |
cin<<auto b; | |
// This way powerMultiply will already have a power of a. | |
int powerMultiply=a; | |
// so you need not do it i<b times, you just have to do | |
// it i < (b-1) times. | |
for(int i =0;i<b;i++) | |
{ | |
// This is cool if the above are corrected. | |
powerMultiply = powerMultiply * b; | |
// Well you need not print result for every iteration, but cool | |
// printing everytimee is great for debugging ya know! | |
std:: cout<< "the result is " powerMultiply<< std::endl; | |
} | |
// cin was a great idea, I din't even get it at all :p knuckle head me | |
// Happy coding! have a great day! | |
// by the way the following is my way of doing it. | |
// before executing this code remove the above or | |
// it may cause errors. | |
#include <iostream> | |
int main() { | |
int a, b; | |
std::cout << "Enter base: "; | |
std::cin >> a; | |
std::cout << "Enter power: "; | |
std::cin >> b; | |
int powerMultiply = 1; | |
for(int i = 0; i < b; i++) { | |
powerMultiply *= a; | |
} | |
std::cout << "the result is " | |
<< powerMultiply | |
<< std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment