Program To Print Histogram of an Array Using C++
"Nice One Program"
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[6]={5,6,9,2,4,3};
int g=a[0],i,j;
for(i=1;i<6;i++)
{ if(a[i]>g)
g=a[i]; }
for(i=0;i<9;i++)
{ cout<<"\n";
for(j=0;j<6;j++)
{ if(a[j]<g)
cout<<" ";
else
cout<<"*"; } g--; }
g=0;
cout<<"\n";
for(i=0;i<9;i++)
{ cout<<endl;
for(j=0;j<6;j++)
{ if(a[j]>=g)
cout<<"*";
else
cout<<" ";
} g++; }
getch();
}
"Nice One Program"
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[6]={5,6,9,2,4,3};
int g=a[0],i,j;
for(i=1;i<6;i++)
{ if(a[i]>g)
g=a[i]; }
for(i=0;i<9;i++)
{ cout<<"\n";
for(j=0;j<6;j++)
{ if(a[j]<g)
cout<<" ";
else
cout<<"*"; } g--; }
g=0;
cout<<"\n";
for(i=0;i<9;i++)
{ cout<<endl;
for(j=0;j<6;j++)
{ if(a[j]>=g)
cout<<"*";
else
cout<<" ";
} g++; }
getch();
}
No comments:
Post a Comment