-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b1d6a6
commit 78d4bdf
Showing
2 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "jac.h" | ||
|
||
void multiply (struct n *head, struct n *end) | ||
{ | ||
double result; | ||
|
||
if (head->next == end || head->next == NULL) | ||
return; | ||
|
||
else { | ||
|
||
if ((head->next)->op == '*') { | ||
result = (head->next)->value * head->value; | ||
head->value = result; | ||
del_next(head); | ||
multiply(head, end); | ||
} | ||
|
||
else | ||
multiply(head->next, end); | ||
} | ||
} | ||
|
||
void divide (struct n *head, struct n *end) { | ||
|
||
double result; | ||
|
||
if (head->next == end || head->next == NULL) | ||
return; | ||
|
||
else { | ||
|
||
if ((head->next)->op == '/') { | ||
result = (head->next)->value / head->value; | ||
head->value = result; | ||
del_next(head); | ||
divide(head, end); | ||
} | ||
|
||
else | ||
divide(head->next, end); | ||
} | ||
} | ||
|
||
void add (struct n *head, struct n *end) { | ||
|
||
double result; | ||
|
||
if (head->next == end || head->next == NULL) | ||
return; | ||
|
||
else { | ||
|
||
if ((head->next)->op == '+' || (head->next)->op == '-') { | ||
|
||
if ((head->next)->op == '+') | ||
result = (head->next)->value +1 * head->value; | ||
|
||
else { | ||
result = (head->next)->value -1 * head->value; | ||
} | ||
|
||
head->value = result; | ||
del_next(head); | ||
add(head, end); | ||
} | ||
|
||
else | ||
add(head->next, end); | ||
} | ||
} | ||
|
||
void del_next (struct n *before_del_next) { | ||
|
||
struct n *temp; | ||
temp = before_del_next->next; | ||
before_del_next->next = temp->next; | ||
free(temp); | ||
|
||
} | ||
|
||
unsigned long factorial(unsigned long f) { | ||
|
||
if ( f == 0 ) | ||
return 1; | ||
return(f * factorial(f - 1)); | ||
} | ||
|
||
int bin_dec(long long n) { | ||
|
||
int dec = 0, i = 0, rem; | ||
|
||
while (n != 0) { | ||
rem = n % 10; | ||
n /= 10; | ||
dec += rem * pow(2, i); | ||
++i; | ||
} | ||
return dec; | ||
} | ||
|
||
long long dec_bin(int n) { | ||
|
||
long long bin = 0; | ||
int rem, i; | ||
|
||
rem = i = 1; | ||
|
||
while (n != 0) { | ||
rem = n % 2; | ||
n /= 2; | ||
bin += rem * i; | ||
i *= 10; | ||
} | ||
|
||
return bin; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdlib.h> | ||
#include <math.h> | ||
|
||
#define MAX 1000 | ||
|
||
struct n{ | ||
double value; | ||
char op; | ||
struct n *next; | ||
char unary; | ||
}; | ||
|
||
void add_item(struct n **ptr, double data, char s); | ||
void print_num(double x); | ||
void remove_spaces(char *str); | ||
void multiply (struct n *head, struct n *end); | ||
void divide (struct n *head, struct n *end); | ||
void add (struct n *head, struct n *end); | ||
void calculate (struct n *head, struct n *end, _Bool *operation); | ||
void del_next(struct n *head); | ||
void unary (struct n *head, struct n *end); | ||
unsigned long factorial(unsigned long f); | ||
int bin_dec(long long n); | ||
long long dec_bin(int n); |