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

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

Procedure Oriented Programming (POP) और Object Oriented Programming (OOP) में अंतर जानने के लिए देखें—POP vs OOP

C और C++ दोनों भाषाओं में महत्वपूर्ण अंतर क्या है जानने के लिए देखें—C vs C++

Flowchart to find average of three numbers

Average of three numbers flowchart

C program to find average of three numbers

#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;
}

C++ program to find average of three numbers

#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 of C C++ program to find average of three numbers

Enter number1: 30
Enter number2: 90
Enter number3: 60
Average of numbers = 60.000000
Enter number1: 3
Enter number2: 4
Enter number3: 7
Average of numbers = 4.66667

Some other related programs in C C++

  1. Sum of two entered numbers
  2. Simple interest
  3. Total and Percent
  4. Swapping values of two variables
  5. Swapping without using third variable
  6. Celsius to Fahrenheit conversion
  7. Find area and circumference of circle
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer