Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// 5. functions
- #include<bits/stdc++.h>
- using namespace std;
- // function declaration
- // (return value type) function_name(type1 name1, type2 name2 ...){}
- int pow(int a,int b){ // calculate (a) to the power of (b)
- // send two (int) into the function and return a (int)
- int ans=1; // identity
- for(int i=1;i<=b;i++) // repeat (b) times
- ans*=a; // means "ans = ans*a"
- return ans; // (ans) is the answer of pow(a,b)
- }
- signed main(){
- int a,b; // The variable a,b int main() is different from
- // the a,b in function pow(), they are independent
- // variable
- cin >> a >> b;
- cout << pow(a,b) << endl; // print the value of pow(a,b)
- int c=pow(a,b);
- // It can also be assigned to the other variable
- cout << c << endl;
- /// ** Don't forget to add ';' at the end of the statement **
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement