Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Bar Chart printing program(By Arrays)

Tuesday, June 7, 2011

#include <iostream.h>
int main()
{
    const int arraysize=10;
    int a[arraysize]={0,0,0,0,0,1,2,4,2,1};
    for (int i=0;i<arraysize;i++)
    {
        if (i==0)
            cout <<" 0 - 9 : ";
        else if (i==100)
            cout <<"  100 : ";
        else
            cout <<i*10<<" - "<<(i*10)+9<<" : ";
        for (int stars=0;stars<a[i];stars++)
        cout <<"*";
        cout <<endl;
    }
    return 0;
}