SHARE
TWEET

Untitled

a guest Feb 27th, 2020 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. struct list {
  4.    float val;
  5.    list* next;
  6.    list* prev;
  7. };
  8.  
  9. list* input(FILE* fp)
  10. {
  11.    list* temp = new list;
  12.    float c;
  13.    fscanf_s(fp, "%f", &c);
  14.    temp->val = c;
  15.    list* head = temp;
  16.    while (fscanf_s(fp,"%f", &c) != EOF)
  17.    {
  18.       temp->next = new list;
  19.       temp->next->prev = temp;
  20.       temp->next->val = c;
  21.       temp = temp->next;
  22.    }
  23.    temp->next = head;
  24.    head->prev = temp;
  25.    return(head);
  26. }
  27.  
  28. float prod(list* left, list* right, list* head)
  29. {
  30.    float a = 1;
  31.    a = a * (right->val + left->val);
  32.    right = right->prev;
  33.    left = left->next;
  34.    while (left != head)
  35.    {
  36.       a = a * (right->val + left->val);
  37.       right = right->prev;
  38.       left = left->next;
  39.    }
  40.    return a;
  41. }
  42.  
  43. int main()
  44. {
  45.    FILE *fp;
  46.    if (fp = fopen("input.txt", "r"))
  47.    {
  48.       list* head = input(fp);
  49.       list* temp_l = head;
  50.       list* temp_r = head->prev;
  51.       float result = prod(temp_l, temp_r, head);
  52.       printf("%f", result);
  53.    }
  54.  
  55.    return 0;
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top