# C PROGRAMS
Array Programs
➤ Find Length of Array
➤ How to Print an Array
➤ Sum of Array Elements
➤ Reverse an Array in C
➤ Copy an Array in C
➤ Merge Two Arrays in C
➤ Merge Two Sorted Arrays
➤ Count Repeated Elements
➤ Find Duplicate Elements
➤ Linear Search in C
➤ Binary Search in C
➤ Insert Element in Array
➤ Delete Element in Array
➤ Display odd-even in Array
➤ Sum & Count of Odd-Even
➤ Count +ve, -ve, & 0
➤ Sum of +ve, -ve Numbers
➤ Avg & Numbers > Avg
➤ Smallest & Largest Element
➤ 1st 2nd Max-Min
➤ Sort Array in C
➤ Search element in Array
➤ Search index of Nth times occurred element
➤ Matrix Programs
Find total, average, and numbers greater than average in array | Here we will write a program to find the total sum and average of array elements. After that also find numbers greater than average in the array.
Program description:- Write a program to find total and average of n given numbers and also find the numbers which are greater than average.
C Program to Find Total, Average, & Numbers Greater than Average in Array
#include<stdio.h>
int main()
{
int a[100], n, i, sum=0;
float avg;
printf("Enter array size [1-100]: ");
scanf("%d",&n);
printf("Enter %d elements: ", n);
// finding sum and average
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
sum += a[i];
}
avg = (float)sum/n;
printf("Sum=%d \t Average=%.2f", sum, avg);
// finding numbers greater than average
printf("\nNumbers greater than average are:\n");
for(i=0; i<n; i++)
{
if(a[i]>avg) printf("%d\t",a[i]);
}
return 0;
}
Output for the different test-cases:-
Enter array size [1-100]: 5
Enter 5 elements: 10 20 5 15 30
Sum=80 Average=16.00
Numbers greater than average are: 20 30
Enter array size [1-100]: 3
Enter 3 elements: 1 2 8
Sum=11 Average=3.67
Numbers greater than average are:
8
The variable sum is initialized with 0, and calculated as sum+=array element. The variable avg (average) is declared as a float because it can be floating data type. The average is calculated as the sum of all elements divided by the number of array elements. Finally, using if condition all elements greater than average will be displayed.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!
Similar C programming examples on Arrays
- Sum of Array elements
- Display even & odd numbers in an array
- Sum and count of even and odd numbers in an array
- Count positive negative and zeros in the array
- Sum of positive and negative numbers
- Average and numbers greater than average in the array
- Find Smallest and largest Array element
- First maximum & minimum, Second maximum & minimum
- Sort a list of an array element
- Search an Array element
- Search position of nth times occurred element in an array
- C program to insert an element in an array
- C program to delete an element in an array
- Passing a multidimensional array to Function
- Find Largest and smallest in a 2D array with their position
- Store temperature of two Cities for a week & display
- Matrix Operations – Addition, Multiplication, Transpose