c++ - Simple power program -


i asking today power program. so, figure out ho , want ask, how add, numbers before lines(like 1 is; 2 is; , etc.). program

#include<iostream> using namespace std;  int exponentiation(int base, int exponent);  int main(void) {   for(int = 0; <= 10; ++i)    cout << exponentiation(i, i) << '\n'; }  int exponentiation(int base, int exponent){  int result = 1; (int = 0; < exponent; ++i) result = result * base; return result; } 

output goes line line

                      ....                            .......                        .............. 

and want make looks this:

                      1 ....                            2 .......                        3 .............. 

i trying make cout loop , add in code above, doesn't work:

           #include<iostream>            using namespace std;            int exponentiation(int base, int exponent);            int main(void) {           for(int c = 1; c < 10; c++)          {            cout << c << " ";            for(int = 0; <= 10; ++i)            cout << exponentiation(i, i) << '\n';             cout << endl;            }             }             int exponentiation(int base, int exponent) {            int result = 1;            (int = 0; < exponent; ++i)            result = result * base;            return result;               } 

you have perfect loop ready , waiting in original program. why need add new one? need add stuff line on print exponentiation(i, i):

int main() {    (int = 0; <= 10; ++i)       cout << (i+1) << "is: " << exponentiation(i, i) << '\n'; } 

it's easy that!


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -