Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char *argv[])
- { double value, base = 2, result;
- if(argc == 2) {
- if(atoi(argv[1]) == 0 || atoi(argv[1]) < 0) {
- fprintf(stderr, "Value error: %s\n", argv[1]);
- exit(0);
- }
- else {
- if(strcmp(argv[1], "e") == 0) {
- value = 2.71828;
- result = log(value) / log(2);
- }
- else {
- value = atoi(argv[1]);
- result = log(value) / log(2);
- }
- }
- }
- else {
- if(atoi(argv[1]) == 0 || atoi(argv[1]) < 0 || atoi(argv[2]) == 0 || atoi(argv[2]) < 0) {
- fprintf(stderr, "Value error: %s, %s\n", argv[1], argv[2]);
- exit(0);
- }
- else {
- if ((strcmp(argv[1], "e") != 0) && (strcmp(argv[2], "e") != 0)){
- value = atoi(argv[1]);
- base = atoi(argv[2]);
- result = log(value) / log(base);
- }
- else if ((strcmp(argv[1], "e") == 0) && (strcmp(argv[2], "e") == 0)) {
- value = 2.71828;
- base = 2.71828;
- result = log(value);
- }
- else if (strcmp(argv[1], "e") == 0) {
- value = 2.71828;
- base = atoi(argv[2]);
- result = log(value) / log(base);
- }
- else if ((strcmp(argv[2], "e") == 0)) {
- value = atoi(argv[1]);
- base = 2.71828;
- result = log(value) / log(base);
- }
- }
- }
- printf("log%.1f(%.1f) = %.2f\n", base, value, result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment