The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Sunday, June 17, 2012

Finding Vertical Histogram of given set of data 2


#include <iostream>#include <iomanip>#include <algorithm>#include <string>#include<conio.h>using namespace std;
#define VALS 30
int main ( void ){   int h[VALS] = { 1, 2, 4, 8, 16, 8, 4, 2, 1, 0, 1, 2, 4, 8, 4, 2,1, 0, 1, 2, 4, 8, 16, 8, 4, 8, 4, 2, 1, 0 };   int height=0;   int y,x;   cout.unsetf(ios::right);   cout.setf(ios::left);   cout << endl;   for (x=0; x<VALS; x++) height = max(height, h[x]);   for (y=height; y>=1; y--)   {       cout << setw(3) << y << "|";       for (x=0; x<VALS; x++)           if (h[x]>=y) cout << " *"; else cout << "  ";       cout << endl;   }   cout << "---+" << string(VALS*2, '-') << endl;   cout << "   |";   for (x=0; x<VALS; x++)   {       if (x<26)           cout << " " << char('a'+x);       else           cout << " " << char('A'+x-26);   }   cout << endl << endl;   getch();   return 0;}


No comments:

Post a Comment