Skip to content

Commit 1e00aea

Browse files
committed
return multiple value using a tuple in c++
1 parent 8281b70 commit 1e00aea

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Cpp_11above/tuple_ex1.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
#include <tuple>
3+
4+
using namespace std;
5+
6+
tuple<int, int, int> myTuple(int num)
7+
{
8+
int square = num*num;
9+
int cube = square*num;
10+
int quad = cube*num;
11+
return make_tuple(square, cube, quad);
12+
}
13+
14+
15+
int main()
16+
{
17+
for(int i=1; i<11; i++)
18+
{
19+
cout << i << "^2 = " << get<0>(myTuple(i)) << "\t\t"
20+
<< i << "^3 = " << get<1>(myTuple(i)) << "\t\t"
21+
<< i << "^4 = " << get<2>(myTuple(i)) << "\n";
22+
}
23+
24+
return 0;
25+
}
26+
/* OUTPUT
27+
28+
1^2 = 1 1^3 = 1 1^4 = 1
29+
2^2 = 4 2^3 = 8 2^4 = 16
30+
3^2 = 9 3^3 = 27 3^4 = 81
31+
4^2 = 16 4^3 = 64 4^4 = 256
32+
5^2 = 25 5^3 = 125 5^4 = 625
33+
6^2 = 36 6^3 = 216 6^4 = 1296
34+
7^2 = 49 7^3 = 343 7^4 = 2401
35+
8^2 = 64 8^3 = 512 8^4 = 4096
36+
9^2 = 81 9^3 = 729 9^4 = 6561
37+
10^2 = 100 10^3 = 1000 10^4 = 10000
38+
39+
*/

0 commit comments

Comments
 (0)