Advertisement
Robert_Manea

Inserare vector

Dec 8th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main(){
  6. int n,i=0, j=0, contor=0;
  7. float v[100];
  8.  
  9.  
  10. printf("introdu n:");
  11. scanf("%d", &n);
  12.  
  13. for(i=0;i<n;i++){
  14. scanf("%f",&v[i]);
  15. }
  16.  
  17.  
  18. i = 0;
  19. while(i < n-1){
  20. if(v[i] * v[i+1] < 0){
  21. for( j = n; j>=i+2;j--){
  22. v[j] = v[j-1];
  23. }
  24. v[i+1] = (v[i] + v[i+1]) / 2;
  25. n++;
  26. i+=2;
  27. }else{
  28. i++;
  29. }
  30. }
  31.  
  32. for(int p = 0; p< n; p++){
  33. printf("%.2f ", v[p]);
  34. }
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement