IvoSilva

[PROG1] Ficha 12 | Exercício 1

Jan 16th, 2012
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void main()
  4. {
  5.     int *v , n = 0 , i , temp = 1 ;
  6.     v = (int *) malloc(sizeof(int)) ;
  7.     while (temp != 0)
  8.     {
  9.         scanf ("%d" , &temp) ;
  10.         if (temp != 0)
  11.         {
  12.             v[n++] = temp ;
  13.             v = (int *) realloc (v , (n + 1) * sizeof(int)) ;
  14.         }
  15.     }
  16.     system ("clear") ;
  17.     printf ("Vector : [ %d | " , (v[0] + v[1]) / 2) ;
  18.     for (i = 1 ; i < n - 1 ; i++) printf ("%d | " , (v[i + 1] + v[i] + v[i - 1]) / 3) ;
  19.     printf ("%d ]\n" , (v[n - 1] + v[n - 2]) / 2) ;
  20.     free (v) ;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment