Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- // Initialize variables
- int n1, i, j = 0, n2 = 0;
- float average_first_last_number;
- printf("Vnesi golemina na nizata\n");
- // Enter the length of the array
- scanf("%d", &n1);
- // Define an array with n1 elements
- float array[n1];
- // Scan elements and assign them at i position in the array
- for(i = 0; i < n1; i++){
- scanf("%f", &array[i]);
- }
- // Calculate the first number and last number average
- average_first_last_number = (array[0] + array[n1-1]) / 2;
- // Iterate through the array
- for(i = 0; i < n1; i++){
- // Check if value is not within interval
- if(array[i] < 4.6 || array[i] > 9.7 ){
- // Check if value is bigger than the average
- if(array[i] > average_first_last_number){
- // Increase the counter to calculate the sub array size
- n2++;
- }
- }
- }
- printf("Prosekot na prviot i posledniot element e: %.2f\n", average_first_last_number);
- printf("Dolzinata na podnizata e: %d\n", n2);
- // Define the sub aray with the size n2
- float subarray[n2];
- // Iterate through the first array again
- for(i = 0; i < n1; i++){
- // Check if the value is not within the interval
- if(array[i] < 4.6 || array[i] > 9.7 ){
- // Check if the value is bigger than the average
- if(array[i] > average_first_last_number){
- // Assign the element of the first array to the second array
- subarray[j] = array[i];
- printf("%.2f ", subarray[j]);
- // Increase the j counter
- j++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement