Write a C C++ program to find average of three numbers

 

Flowchart

Average of three numbers flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int n1,n2,n3;
float avg;
printf(“Enter number1: “);
scanf(“%d”,&n1);
printf(“Enter number2: “);
scanf(“%d”,&n2);
printf(“Enter number3: “);
scanf(“%d”,&n3);
avg=(n1+n2+n3)/3.0;
printf(“Average of numbers = %f”,avg);
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int n1,n2,n3;
float avg;
cout<<“Enter number1: “;
cin>>n1;
cout<<“Enter number2: “;
cin>>n2;
cout<<“Enter number3: “;
cin>>n3;
avg=(n1+n2+n3)/3.0;
cout<<“Average of numbers = “<<avg;
return 0;
}

 

Output

Average of three numbers output

 

Published by

admin

I am a computer teacher, programmer and web developer