Coding Practice

Find how many numbers in a array are greater than the average and then reverse the arrays numbers

1. Take n numbers in an array. Do the following operations
a. Find how many numbers in the array are greater than the average value of the array elements.
b. Reverse the array without using any library function.

Sample Input

Output

Array element: 4

10 20 30 40

Numbers greater than average value: 2

Reversed array: 40 30 20 10

Array element: 5

1 2 3  4 65

Numbers greater than average value: 1

Reversed array: 65 4 3 2 1

Sample Output
Array element: 4
10
20
30
40

Numbers greater than average value: 2
Reversed array: 40 30 20 10


Process returned 0 (0x0)   execution time : 15.815 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    int i, size, arr[50], sum = 0, avg, count = 0;

    printf("Array element: ");
    scanf("%d", &size);

    for(i = 0; i < size; i++)
    {
        scanf("%d", &arr[i]);
        sum = sum + arr[i];
    }

    avg = sum / size;

    for(i = 0; i < size; i++)
    {
        if(avg > arr[i])
        {
            count++;
        }
    }
    printf("\nNumbers greater than average value: %d\n", count);

    printf("Reversed array: ");
    for(i = size - 1; i >= 0; i--)
    {
        printf("%d ", arr[i]);
    }
    printf("\n\n");

    return 0;
}
Sample Output
Array element: 5
1
2
3
4
65

Numbers greater than average value: 4
Reversed array: 65 4 3 2 1


Process returned 0 (0x0)   execution time : 15.311 s
Press any key to continue.
Change Theme
X