-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass2-1.cpp
More file actions
27 lines (25 loc) · 1.04 KB
/
class2-1.cpp
File metadata and controls
27 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Example program
#include <iostream> // essential libraries
#include <string> // essential libraries
using namespace std; // std
int main() {
float saitama( float j ); // function declaration
float jojo[10];
int i = 0; // array declaration , type int, length = 10
while ( i < 10 ){ // loop to assign elements of jojo array incremently
jojo[i] = saitama(i); // The i-th element of array jojo is being assigned the value returned by the function saitama with the input parameter as "i"
i++;
}
i = 0;
while ( i < 10 ){
cout << "The element number "<<i + 1<<" of the array jojo is " << jojo[i] <<endl;
i++;
}
}
float saitama(float j){ // function definition
if ( j < 1 ) {
cout << "The answer is less than 1, therefore not allowed" << endl << endl;
return 0; // float saitama(float j) - expect a result of float type, but if j = 0 then nothing is returned, which results in an error. "return 0" helps to remove that error
}
else return ((j*j*j + 1)/(j*j));
}