Program to find average of three numbers using function

 

Coding in C

#include<stdio.h>
float avg(int,int,int);
int main()
{
int a,b,c;
printf(“Enter three numbers: “);
scanf(“%d%d%d”,&a,&b,&c);
printf(“Average of numbers = %f”,avg(a,b,c));
return 0;
}
float avg(int x, int y, int z)
{
return (x+y+z)/3.0;
}

 

Coding in C++

#include<iostream>
using namespace std;
float avg(int,int,int);
int main()
{
int a,b,c;
cout<<“Enter three numbers: “;
cin>>a>>b>>c;
cout<<“Average of numbers = “<<avg(a,b,c);
return 0;
}
float avg(int x, int y, int z)
{
return (x+y+z)/3.0;
}

 

Output

C C++ program to find average of three numbers using function

 

Published by

admin

I am a computer teacher, programmer and web developer