Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct list {
- float val;
- list* next;
- list* prev;
- };
- list* input(FILE* fp)
- {
- list* temp = new list;
- float c;
- fscanf_s(fp, "%f", &c);
- temp->val = c;
- list* head = temp;
- while (fscanf_s(fp,"%f", &c) != EOF)
- {
- temp->next = new list;
- temp->next->prev = temp;
- temp->next->val = c;
- temp = temp->next;
- }
- temp->next = head;
- head->prev = temp;
- return(head);
- }
- float prod(list* left, list* right, list* head)
- {
- float a = 1;
- a = a * (right->val + left->val);
- right = right->prev;
- left = left->next;
- while (left != head)
- {
- a = a * (right->val + left->val);
- right = right->prev;
- left = left->next;
- }
- return a;
- }
- int main()
- {
- FILE *fp;
- if (fp = fopen("input.txt", "r"))
- {
- list* head = input(fp);
- list* temp_l = head;
- list* temp_r = head->prev;
- float result = prod(temp_l, temp_r, head);
- printf("%f", result);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement