Advertisement
boyan16-z

mean value in the middle

Mar 21st, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include "StdAfx.h"
  2. #include <stdio.h>
  3. #include <malloc.h>
  4. #include <stdlib.h>
  5.  
  6. int main(){
  7. int *a;
  8. int i,n, s=0,sr;
  9.  
  10. printf("Enter the size : ");
  11. scanf_s("%d", &n);
  12. a = (int*)malloc(n * sizeof(int));
  13.  
  14. for (i = 0; i < n; i++)
  15. {
  16. printf("a[%d] = ", i);
  17. scanf_s("%d", &a[i]);
  18. s += a[i];
  19. }
  20.  
  21. sr =int(s / n);
  22. printf("%d", sr);
  23.  
  24. n = n + 1;
  25. a = (int*)realloc(a,n * sizeof(int));
  26.  
  27. for (i = n; i > n / 2; i--){
  28. a[i] = a[i - 1];
  29. }
  30. a[n / 2] = sr;
  31. printf("\nResult\n");
  32. for (i = 0; i < n; i++){
  33. printf("a[%d] = %d ", i, a[i]);
  34. }
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement