samedi 7 novembre 2020

c++ program to raise a number to power gives error (expected unqualified id before 'for') [closed]

for loop isn't working in this cpp program

I tried changing for conditions but that doesn't work either.

#include <iostream>

using namespace std;

int num(int num1, int num2) {
    int result = 1;

    for (int i = 0; i < num2; i++) {
        result = result * num2;
        return result;
    }
}
int main() {
    cout << num(2, 3);
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire