Print Friendly and PDF
(Bar Chart) One interesting application of computers is drawing graphs and bar charts. Write a program that reads five numbers (each between 1 and 30). Assume that the user enters only valid values. For each number that is read, your program should print a line containing that number of adjacent asterisks. For example, if your program reads the number 7, it should print *******. Solution:
(Bar Chart) One interesting application of computers is drawing graphs and bar charts.

Write a program that reads five numbers (each between 1 and 30). Assume that the user enters only valid values. 
For each number that is read, your program should print a line containing that number of adjacent asterisks. 

For example, if your program reads the number 7, it should print *******.

Solution:

#include < iostream>
using namespace std;
int main()
{
int a, b, c, d, e;
cout << "Enter five integers (between 1 and 30) : ";
cin >> a >> b >> c >> d >> e;
for( int i = 1; i <= a; i++)
{
cout << "*";
}c
out << endl;
for( int i = 1; i <= b; i++)
{
cout << "*";
}c
out << endl;

for( int i = 1; i <= c; i++)
{
cout << "*";
}c
out << endl;
for( int i = 1; i <= d; i++)
{
cout << "*";
}c
out << endl;
for( int i = 1; i <= e; i++)
{
cout << "*";
}c
out << endl;
//for pause
system("PAUSE") ;
return 0;
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: