Thursday, 5 February 2015

C++ Program to read a digit element in an array & print horizontal histogram

C++ Program to read a digit element in an array & print horizontal histogram.

#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],n,i,j,max=0;
clrscr();
cout<<"Enter the no. of element in an array:\n";
cin>>n;
for(i=0;i<n;i++)
{
   cin>>a[i];
   if(a[i]>max)
   max=a[i];
}
for(i=0;i<n;i++)
   {
      for(j=0;j<max;j++)
{
if(j<a[i])
 cout<<"* ";
 else
 cout<<" ";
}
cout<<"\n";

   }
getch();
}

No comments:

Post a Comment