hozer

DDS - VitjaLab

May 27th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4.  
  5. typedef struct _node {
  6.     float data;
  7.     struct _node *next, *prev;
  8. } node;
  9.  
  10.  
  11. node *addNode(node **head, node *tail, float num)
  12. {
  13.     node * n = (node*) malloc(sizeof(node));
  14.     n->next = NULL;
  15.     n->prev = tail;
  16.     n->data = num;
  17.     if (tail)
  18.     {
  19.         tail->next = n;
  20.     }
  21.     tail = n;
  22.     if (!*head) *head = tail;
  23.     return tail;
  24. }
  25.  
  26. int main(){
  27.  
  28.     node *i, *j;
  29.     float out = 1.0, t = 1.0;
  30.     node *head = NULL;
  31.     node *tail = NULL;
  32.     while (1)
  33.     {
  34.         scanf("%f", &t);
  35.         if (t == .0) break;
  36.         tail = addNode(&head, tail, t);
  37.  
  38.     }
  39.     i = head;
  40.     j = tail;
  41.     while (i && j)
  42.     {
  43.         out *= i->data - j->data;
  44.         printf("%.3f ", i->data);
  45.         i = i->next;
  46.         j = j->prev;
  47.     }
  48.     printf("\n%.3f\n", out);
  49.     getch();
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment