# C Program to Find the Sum and Average of Three Numbers

In this article, we are going to write a c program to find the sum and average of three numbers.

We will make this program in the following way -:

• C Program to Find the Sum and Average of Three Numbers (Simple Way)
• C Program to Find the Sum and Average of Three Numbers Using Function
• C Program to Find the Sum and Average of Three Numbers Using Array

Let’s understand all these methods one by one.

Page Contents

## C Program to Find the Sum and Average of Three Numbers

To get the sum and average of three numbers, we have to first take three numbers from the user, then add these numbers and find their average.

formula to calculate sum and average of three numbers

Sum = a+b+c;

Average = sum/count

Now let’s start programming.

## C Program to Find the Sum and Average of Three Numbers (Simple Way)

### Algorithm

• Program Start
• Declaring Variables
• Input Three Numbers from User
• Calculating Sum of Three Numbers (sum = x + y + z)
• Displaying the Sum of Three Numbers
• Calculating Average of Three Numbers (average = sum/count)
• Displaying the Average of Three Numbers
• Program End

### Program

``````//C Program to Find the Sum and Average of Three Numbers (Simple Way)

#include<stdio.h>
int main()
{
//Declaring Three Variables

int x, y, z, sum;
float avg;

printf("Enter Three Numbers : \n");
scanf("%d %d %d",&x, &y, &z);     //Input Numbers

//Calculating Sum of three numbers

sum = x + y +z;
printf("Sum of Three Numebers is : %d", sum);

//Calculating Average of three numbers

avg=sum/3;
printf("\n Average of Three Numebers is : %f", avg);

return 0;
}``````

### Output

``````Enter Three Numbers :
10
2
38

Sum of Three Numebers is : 50
Average of Three Numebers is : 16.000000``````

### Program Explanation

• In this program, we first declared four variables x, y, z, sum.
• After that created another variable named avg with the help of float data type.
• In this avg variable, we will store the average of the number three and in the sum variable, we will store the sum of the number three.
• After declaring the variables, we got input three numbers from the user and store those values ​​in the x, y, z variables.
• After this, we Calculate the sum of three numbers using the formula (sum = x + y + z ) and stored its result in the sum variable.
• After that, we print the sum of three numbers.
• After this, we Calculate the average of three numbers using the formula (average = sum/count) and stored its result in the avg variable.
• Finally, we printed the stored value in this avg variable on the screen with the help of printf() function.

## C Program to Find the Sum and Average of Three Numbers Using Function

To find the sum and average of three numbers through a function, first you need to know about the function. You can read about the function from the link given below.

### Algorithm

• Program Start
• Declaring variables
• Input Numbers
• Calling Function to calculate Sum
• Print the Sum of three Numbers
• Calling Function to calculate Average
• Print the Average of three Numbers
• Program End

### Program

``````//C Program to Find the Sum and Average of Three Numbers Using Function

#include<stdio.h>
int sum(int, int, int);
void average(int);
int main()
{
//Declaring Variables
int x, y, z, s;

//Input Numbers
printf("Enter Three Numbers : \n");
scanf("%d %d %d",&x, &y, &z);

//Calling Function to find the Sum of three numbers
s = sum(x,y,z);
printf("Sum of Three Numbers is : %d \n", s);

//Calling Function to find the Average of three numbers
average(s);

}
int sum(int a, int b, int c)
{
return (a+b+c);
}
void  average(int sum)
{   float avg;
avg=sum/3;
printf("Average of Three Numebers is : %f", avg);
}``````

### Output

``````Enter Three Numbers :
10
38
23

Sum of Three Numbers is : 71
Average of Three Numebers is : 23.00000``````

## C Program to Find the Sum and Average of Three Numbers Using Array

To find the sum and average of three numbers through an Array, first you need to know about the Array. You can read about the Array from the link given below.

• Array in C Language

### Algorithm

• Program Start
• Declaring variables
• Input Numbers
• Calculating Sum
• Print the Sum of three Numbers
• Calculating Average
• Print the Average of three Numbers
• Program End

### Program

``````//C Program to Find the Sum and Average of Three Numbers Using Array

#include<stdio.h>
void main()
{
//Declaring  Variables

int i, sum = 0, a;
float avg;

printf("Enter Three Numbers : \n");
for(i=0; i<3; i++)
{
scanf("%d",&a[i]);  //Input Numbers
}

for(i=0; i<3;i++)
{
sum = sum + a[i];  //Input Numbers
}
printf("Sum of Three Numebers is : %d", sum);

avg=sum/3.0;
printf("\n Average of Three Numebers is : %f", avg);

}``````

### Output

``````Enter Three Numbers :
38
23
38

Sum of Three Numbers is : 99
Average of Three Numebers is : 33.000000``````

## Conclusion

So friends, in this article, we have made a c program to calculate the sum and average of three numbers in three different ways.

• C Program to Find the Sum and Average of Three Numbers (Simple Way)
• C Program to Find the Sum and Average of Three Numbers Using Function
• C Program to Find the Sum and Average of Three Numbers Using Array

If you have difficulty to understand any program or have any doubts or questions, then tell me in the comment below. Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging