C++ tutorial, C++ programs, C++ Exercises, C++ Example Programs

Friday, November 4, 2011

Program Average Algorithm and Flowchart

Q: Write a program to input three numbers, and calculate and show their average

Today, we will discuss a simple C++ program that inputs three numbers and calculates and shows average of these numbers.

Algorithm: Average

Calculates average of three numbers.

1. Start
2. Include iostream.h [Note: this step is only for C++].
3. Declare 5 float variables n1,n2,n3, total and avergae.
4. Display a message (prompt) on screen "Enter First Number:"
5. Input n1.
6. Display a message (prompt) on screen "Enter Second Number:"
7. Input n2.
7. Display a message (prompt) on screen "Enter Third Number:"
8. Input n3.
9. Calculate total= n1 + n2 + n3
10. Calculate average = total / 3
11. Show a message "Average=" and value stored in average variable.
12. Stop


C++ Program To Calculate Average of Three Numbers Input by User at Run time
C++ Program To Calculate Average of Three Numbers Input by User at Run time

Simple C++ Program To Calculate Average of Three Numbers With Algorithm and Flow chart
Simple C++ Program To Calculate Average of Three Numbers With Algorithm and Flow chart 

Source code for Dev C++ & other Modern C++ Compilers / IDEs

#include<iostream>
using namespace std;
int main()

{

float n1,n2,n3,total,average;
cout << "Enter First Number:";
cin>>n1;
cout<<"Enter Second Number:";
cin>>n2;
cout<<"Enter Third Number:";
cin>>n3;

total=n1+n2+n3;
average=total/3;

cout<<"average="<<average;
return 0;

}

A Sample Output of Program

Enter First Number:10
Enter Second Number:20
Enter Third Number:30
average=20
--------------------------------
Process exited after 26.5 seconds with return value 0
Press any key to continue . . .

Program Source Code for Turbo C++ 3.0: C++ Program To Calculate Average of Three Numbers With Algorithm and Flow chart

#include<iostream.h>

int main()

{

float n1,n2,n3,total,average;

cout << "Enter First Number:";

cin>>n1;

cout<<"Enter Second Number:";

cin>>n2;

cout<<"Enter Third Number:";

cin>>n3;

total=n1+n2+n3;

average=total/3;

cout<<"average="<<average;

return 0;

}

Share:

0 comments:

Post a Comment

We Love To Hear From You!

EasyCPPprogramming.blogspotcom

Labels