Skip to main content

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


Flowchart

Flowchart to find average

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

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