Last active
April 25, 2021 08:53
-
-
Save CWKSC/c85917f90fac25266ba30e231414e3d3 to your computer and use it in GitHub Desktop.
One for loop to print diamond star
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int f(int x) { | |
return (4) * ((x - 1) / (-1)) * ((x - 2) / (-2)) * ((x - 3) / (-3)) * ((x - 4) / (-4)) * ((x - 5) / (-5)) * ((x - 6) / (-6)) * ((x - 7) / (-7)) * ((x - 8) / (-8)) * ((x - 9) / (-9)) * ((x - 10) / (-10)) * ((x - 11) / (-11)) * ((x - 12) / (-12)) * ((x - 13) / (-13)) * ((x - 14) / (-14)) * ((x - 15) / (-15)) * ((x - 16) / (-16)) * ((x - 17) / (-17)) + ((x - 0) / (1)) * (1) * ((x - 2) / (-1)) * ((x - 3) / (-2)) * ((x - 4) / (-3)) * ((x - 5) / (-4)) * ((x - 6) / (-5)) * ((x - 7) / (-6)) * ((x - 8) / (-7)) * ((x - 9) / (-8)) * ((x - 10) / (-9)) * ((x - 11) / (-10)) * ((x - 12) / (-11)) * ((x - 13) / (-12)) * ((x - 14) / (-13)) * ((x - 15) / (-14)) * ((x - 16) / (-15)) * ((x - 17) / (-16)) + ((x - 0) / (2)) * ((x - 1) / (1)) * (3) * ((x - 3) / (-1)) * ((x - 4) / (-2)) * ((x - 5) / (-3)) * ((x - 6) / (-4)) * ((x - 7) / (-5)) * ((x - 8) / (-6)) * ((x - 9) / (-7)) * ((x - 10) / (-8)) * ((x - 11) / (-9)) * ((x - 12) / (-10)) * ((x - 13) / (-11)) * ((x - 14) / (-12)) * ((x - 15) / (-13)) * ((x - 16) / (-14)) * ((x - 17) / (-15)) + ((x - 0) / (3)) * ((x - 1) / (2)) * ((x - 2) / (1)) * (3) * ((x - 4) / (-1)) * ((x - 5) / (-2)) * ((x - 6) / (-3)) * ((x - 7) / (-4)) * ((x - 8) / (-5)) * ((x - 9) / (-6)) * ((x - 10) / (-7)) * ((x - 11) / (-8)) * ((x - 12) / (-9)) * ((x - 13) / (-10)) * ((x - 14) / (-11)) * ((x - 15) / (-12)) * ((x - 16) / (-13)) * ((x - 17) / (-14)) + ((x - 0) / (4)) * ((x - 1) / (3)) * ((x - 2) / (2)) * ((x - 3) / (1)) * (2) * ((x - 5) / (-1)) * ((x - 6) / (-2)) * ((x - 7) / (-3)) * ((x - 8) / (-4)) * ((x - 9) / (-5)) * ((x - 10) / (-6)) * ((x - 11) / (-7)) * ((x - 12) / (-8)) * ((x - 13) / (-9)) * ((x - 14) / (-10)) * ((x - 15) / (-11)) * ((x - 16) / (-12)) * ((x - 17) / (-13)) + ((x - 0) / (5)) * ((x - 1) / (4)) * ((x - 2) / (3)) * ((x - 3) / (2)) * ((x - 4) / (1)) * (5) * ((x - 6) / (-1)) * ((x - 7) / (-2)) * ((x - 8) / (-3)) * ((x - 9) / (-4)) * ((x - 10) / (-5)) * ((x - 11) / (-6)) * ((x - 12) / (-7)) * ((x - 13) / (-8)) * ((x - 14) / (-9)) * ((x - 15) / (-10)) * ((x - 16) / (-11)) * ((x - 17) / (-12)) + ((x - 0) / (6)) * ((x - 1) / (5)) * ((x - 2) / (4)) * ((x - 3) / (3)) * ((x - 4) / (2)) * ((x - 5) / (1)) * (1) * ((x - 7) / (-1)) * ((x - 8) / (-2)) * ((x - 9) / (-3)) * ((x - 10) / (-4)) * ((x - 11) / (-5)) * ((x - 12) / (-6)) * ((x - 13) / (-7)) * ((x - 14) / (-8)) * ((x - 15) / (-9)) * ((x - 16) / (-10)) * ((x - 17) / (-11)) + ((x - 0) / (7)) * ((x - 1) / (6)) * ((x - 2) / (5)) * ((x - 3) / (4)) * ((x - 4) / (3)) * ((x - 5) / (2)) * ((x - 6) / (1)) * (7) * ((x - 8) / (-1)) * ((x - 9) / (-2)) * ((x - 10) / (-3)) * ((x - 11) / (-4)) * ((x - 12) / (-5)) * ((x - 13) / (-6)) * ((x - 14) / (-7)) * ((x - 15) / (-8)) * ((x - 16) / (-9)) * ((x - 17) / (-10)) + ((x - 0) / (8)) * ((x - 1) / (7)) * ((x - 2) / (6)) * ((x - 3) / (5)) * ((x - 4) / (4)) * ((x - 5) / (3)) * ((x - 6) / (2)) * ((x - 7) / (1)) * (0) * ((x - 9) / (-1)) * ((x - 10) / (-2)) * ((x - 11) / (-3)) * ((x - 12) / (-4)) * ((x - 13) / (-5)) * ((x - 14) / (-6)) * ((x - 15) / (-7)) * ((x - 16) / (-8)) * ((x - 17) / (-9)) + ((x - 0) / (9)) * ((x - 1) / (8)) * ((x - 2) / (7)) * ((x - 3) / (6)) * ((x - 4) / (5)) * ((x - 5) / (4)) * ((x - 6) / (3)) * ((x - 7) / (2)) * ((x - 8) / (1)) * (9) * ((x - 10) / (-1)) * ((x - 11) / (-2)) * ((x - 12) / (-3)) * ((x - 13) / (-4)) * ((x - 14) / (-5)) * ((x - 15) / (-6)) * ((x - 16) / (-7)) * ((x - 17) / (-8)) + ((x - 0) / (10)) * ((x - 1) / (9)) * ((x - 2) / (8)) * ((x - 3) / (7)) * ((x - 4) / (6)) * ((x - 5) / (5)) * ((x - 6) / (4)) * ((x - 7) / (3)) * ((x - 8) / (2)) * ((x - 9) / (1)) * (1) * ((x - 11) / (-1)) * ((x - 12) / (-2)) * ((x - 13) / (-3)) * ((x - 14) / (-4)) * ((x - 15) / (-5)) * ((x - 16) / (-6)) * ((x - 17) / (-7)) + ((x - 0) / (11)) * ((x - 1) / (10)) * ((x - 2) / (9)) * ((x - 3) / (8)) * ((x - 4) / (7)) * ((x - 5) / (6)) * ((x - 6) / (5)) * ((x - 7) / (4)) * ((x - 8) / (3)) * ((x - 9) / (2)) * ((x - 10) / (1)) * (7) * ((x - 12) / (-1)) * ((x - 13) / (-2)) * ((x - 14) / (-3)) * ((x - 15) / (-4)) * ((x - 16) / (-5)) * ((x - 17) / (-6)) + ((x - 0) / (12)) * ((x - 1) / (11)) * ((x - 2) / (10)) * ((x - 3) / (9)) * ((x - 4) / (8)) * ((x - 5) / (7)) * ((x - 6) / (6)) * ((x - 7) / (5)) * ((x - 8) / (4)) * ((x - 9) / (3)) * ((x - 10) / (2)) * ((x - 11) / (1)) * (2) * ((x - 13) / (-1)) * ((x - 14) / (-2)) * ((x - 15) / (-3)) * ((x - 16) / (-4)) * ((x - 17) / (-5)) + ((x - 0) / (13)) * ((x - 1) / (12)) * ((x - 2) / (11)) * ((x - 3) / (10)) * ((x - 4) / (9)) * ((x - 5) / (8)) * ((x - 6) / (7)) * ((x - 7) / (6)) * ((x - 8) / (5)) * ((x - 9) / (4)) * ((x - 10) / (3)) * ((x - 11) / (2)) * ((x - 12) / (1)) * (5) * ((x - 14) / (-1)) * ((x - 15) / (-2)) * ((x - 16) / (-3)) * ((x - 17) / (-4)) + ((x - 0) / (14)) * ((x - 1) / (13)) * ((x - 2) / (12)) * ((x - 3) / (11)) * ((x - 4) / (10)) * ((x - 5) / (9)) * ((x - 6) / (8)) * ((x - 7) / (7)) * ((x - 8) / (6)) * ((x - 9) / (5)) * ((x - 10) / (4)) * ((x - 11) / (3)) * ((x - 12) / (2)) * ((x - 13) / (1)) * (3) * ((x - 15) / (-1)) * ((x - 16) / (-2)) * ((x - 17) / (-3)) + ((x - 0) / (15)) * ((x - 1) / (14)) * ((x - 2) / (13)) * ((x - 3) / (12)) * ((x - 4) / (11)) * ((x - 5) / (10)) * ((x - 6) / (9)) * ((x - 7) / (8)) * ((x - 8) / (7)) * ((x - 9) / (6)) * ((x - 10) / (5)) * ((x - 11) / (4)) * ((x - 12) / (3)) * ((x - 13) / (2)) * ((x - 14) / (1)) * (3) * ((x - 16) / (-1)) * ((x - 17) / (-2)) + ((x - 0) / (16)) * ((x - 1) / (15)) * ((x - 2) / (14)) * ((x - 3) / (13)) * ((x - 4) / (12)) * ((x - 5) / (11)) * ((x - 6) / (10)) * ((x - 7) / (9)) * ((x - 8) / (8)) * ((x - 9) / (7)) * ((x - 10) / (6)) * ((x - 11) / (5)) * ((x - 12) / (4)) * ((x - 13) / (3)) * ((x - 14) / (2)) * ((x - 15) / (1)) * (4) * ((x - 17) / (-1)) + ((x - 0) / (17)) * ((x - 1) / (16)) * ((x - 2) / (15)) * ((x - 3) / (14)) * ((x - 4) / (13)) * ((x - 5) / (12)) * ((x - 6) / (11)) * ((x - 7) / (10)) * ((x - 8) / (9)) * ((x - 9) / (8)) * ((x - 10) / (7)) * ((x - 11) / (6)) * ((x - 12) / (5)) * ((x - 13) / (4)) * ((x - 14) / (3)) * ((x - 15) / (2)) * ((x - 16) / (1)) * (1); | |
} | |
int main(int argc, char* argv[]) { | |
for (int i = 0; i < 17; i += 2) { | |
std::cout << std::string(f(i), ' ') << std::string(f(i + 1), '*') << std::endl; | |
} | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/CWKSC/Lagrange-Polynomial | |
// https://github.com/CWKSC/MyLib_Csharp | |
(double, double)[] points = { | |
(0, 4), | |
(1, 1), | |
(2, 3), | |
(3, 3), | |
(4, 2), | |
(5, 5), | |
(6, 1), | |
(7, 7), | |
(8, 0), | |
(9, 9), | |
(10, 1), | |
(11, 7), | |
(12, 2), | |
(13, 5), | |
(14, 3), | |
(15, 3), | |
(16, 4), | |
(17, 1) | |
}; | |
LagrangePolynomial fx = new(points); | |
fx.Generate().Printlnln(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment