Advertisement
Guest User

podniza#2

a guest
Apr 1st, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. // Initialize variables
  7. int n1, i, j = 0, n2 = 0;
  8. float average_first_last_number;
  9. printf("Vnesi golemina na nizata\n");
  10. // Enter the length of the array
  11. scanf("%d", &n1);
  12. // Define an array with n1 elements
  13. float array[n1];
  14. // Scan elements and assign them at i position in the array
  15. for(i = 0; i < n1; i++){
  16. scanf("%f", &array[i]);
  17. }
  18. // Calculate the first number and last number average
  19. average_first_last_number = (array[0] + array[n1-1]) / 2;
  20.  
  21. // Iterate through the array
  22. for(i = 0; i < n1; i++){
  23. // Check if value is not within interval
  24. if(array[i] < 4.6 || array[i] > 9.7 ){
  25. // Check if value is bigger than the average
  26. if(array[i] > average_first_last_number){
  27. // Increase the counter to calculate the sub array size
  28. n2++;
  29. }
  30. }
  31. }
  32. printf("Prosekot na prviot i posledniot element e: %.2f\n", average_first_last_number);
  33. printf("Dolzinata na podnizata e: %d\n", n2);
  34. // Define the sub aray with the size n2
  35. float subarray[n2];
  36. // Iterate through the first array again
  37. for(i = 0; i < n1; i++){
  38. // Check if the value is not within the interval
  39. if(array[i] < 4.6 || array[i] > 9.7 ){
  40. // Check if the value is bigger than the average
  41. if(array[i] > average_first_last_number){
  42. // Assign the element of the first array to the second array
  43. subarray[j] = array[i];
  44. printf("%.2f ", subarray[j]);
  45. // Increase the j counter
  46. j++;
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement