commit b2f43c1584e057cc8ee613c07815b63f49ee8621 Author: nedko Date: Mon Jul 22 15:21:42 2024 +0300 Added code diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4a56e31 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: + g++ main.cpp -o gamma + +.PHONY: all diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..93a147f --- /dev/null +++ b/main.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include + +using namespace std; + +void usage (const char *name) +{ + cout << "Usage: " << name << " [max input] [max output] [factor]" << endl; +} + +int main(int argc, char **argv) +{ + vector args(&(argv[1]), &(argv[argc])); + double gamma = 2.2; + int max_in = 255; + int max_out = 255; + int line_size = 80; + int line_count; + int count; + double val; + int output; + + if (args.size() < 3) + { + usage(argv[0]); + return -1; + } + + max_in = stoi(args[0]); + max_out = stoi(args[1]); + gamma = stod(args[2]); + + count = to_string(max_out).size(); + line_count = line_size / (count + 2); + line_count -= line_count % 8; + for (int i = 0; i <= max_in; ++i) + { + val = i; + val /= max_in; + val = pow(val, gamma); + val *= max_out; + val += 0.5; + output = val; + + printf("%*d, ", count, output); + + if ((i + 1) % line_count == 0) + { + printf("\n"); + } + } + + printf("\n"); + return 0; +}