+ 2
I have a difficult challenge for you (C++ only)
That is my code, you must follow all the rules, if it is possible, in C++ https://code.sololearn.com/cmlm0M36958k/?ref=app
6 ответов
+ 2
#include <iostream>
using namespace std;
int power(int x, int y){
int z = x;
if (y==0)
return 1;
else if (y < 0){
return -1;
}
else{
for(int i = 1; i < y; i++){
z *= x;
}
return z;
}
}
float sine(float o, float h){
float x = o / h;
return x;
}
int main() {
int x = power(5,3);
if (x == -1)
cout<<"exponent cant be negative"<<endl;
else
cout<<x<<endl;
float y = sine(2.5,5);
cout<<y<<endl;
cout<<"you are going to put that code into a function and create two more functions. Paste your code in the response section below that satisfies these requirements:\nCreate a function called pow that accepts two integers that represent the base and the exponent. The exponent should not permit negative values.Use the code you created in the previous module for some of this functionality but add additional code The additional code should make use of an if statement to check the exponent value. If it is 0, then immediately return 1 otherwise calculate the power and return the result.Show sample code that will call the function and get the result.For the second function you will compute the sine of an angle. Your function should accept the opposite and hypotenuse lengths and return the sine value. The formula for sine is: sin = opposite / hypotenuse where / is used to denote division";
return 0;
}
+ 1
yay xD more more!!
0
wow!
0
That's right xD
0
Wait, I need to think hahaha
0
@Mooaholic
https://code.sololearn.com/c6lhh71D3YPF/?ref=app that is my second challenge