Program To Calculate Average In C

Introduction:

C is one of the most potent and flexible programming languages available today. Any C program has to understand how to compute averages and other mathematical operations. The fundamental idea of enables programmers to efficiently examine and work with data.

We shall examine the typical world of C programming in this essay. We’ll talk about averages, how to calculate them, and how to successfully use them to planning. Whether you are a seasoned C programmer or just getting started, this article will provide you with insightful knowledge and a clear understanding of what average infeels are like.
The sum of a group of numbers divided by the total number is the average. It can be characterized as

Average is equal to the total of all values divided by the total number of values.

Program To Calculate Average In C

Implementation

This algorithm’s implementation is shown below:

#include<stdio.h>
void main()
{
    int i,n,sum=0 ;double aver=0;
    printf("enter the number:");
    scanf("%d",&n);
    for(i=1;i<=10;i++){
        sum=sum+i;
        aver=sum/(double)10;
    }
 printf("The sum of 10 no is :%d\n",sum);
 printf("The Average is :%lf",aver);
}

Input :Enter the number:6

Output:
The sum of 6 no is :21
The Average is :2.100000

Implementation 2

Implementation of this algorithm is given below

#include <stdio.h>

int main() {
    int data[] = {10, 20, 30, 40, 50}; // Sample data
    int n = sizeof(data) / sizeof(data[0]);
    int sum = 0;

    for (int i = 0; i < n; i++) {
        sum += data[i];
    }

    float average = (float)sum / n;
    printf("The average is: %.2f", average);
    return 0;
}

Output : The average is: 30.00

Understanding Conditional Statements in C Programming, If Else in C

1 thought on “Program To Calculate Average In C”

Leave a Comment