Finding the series / Getting the output of this type:

* * * * * * * * * *
* * * *    * * * * *
* * *          * * * *
* *                * * *
*                      * *
*                         *

//This code takes an input from the user, and verifies whether its a even no. or an odd no.. If it is an odd number gives the output, else(If it is a even no.)  it prints the message on the screen that please enter an odd no.and doesn't prints the output.

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int size,left,right,count,mid;
    cout<<"Enter the size of the series(width) :";
    cin>>size;
    if(size%2==0)
    {
        cout<<"Its even number, series won't be accurate, please give any odd number....";
        return 0;
    }
    round(mid);
    //size=9;
    count=1;
    left=right=mid=((size+1)/2);


    for(int j=0;j<=((size+1)/2);j++)///or///for(int j=0;j<(size/2)+1;j++)
    {
        for(int i=0;i<=size;i++)
        {
            //cout<<"left = "<<left<<" right = "<<right<<" mid = "<<mid<<endl;
            if((i<left)||(left==right)||(i>=right))
                cout<<" * ";
            else
                cout<<"   ";
        }
        left--;con
        right++;
        cout<<endl;
    }
}
/***
Explanation:


1 2 3 4 5 6 7 8 9 10
* * * * * * * * * *
* * * *    * * * * *
* * *          * * * *
* *                * * *
*                      * *
*                          *
============================
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* * * * * * * * * * * * * * * * * * * * *1
* * * * * * * * * *    * * * * * * * * * *2
* * * * * * * * *          * * * * * * * * *3
* * * * * * * *                * * * * * * * *4
* * * * * * *                      * * * * * * *5
* * * * * *                            * * * * * *6
* * * * *                                  * * * * *7
* * * *                                        * * * *8
* * *                                              * * *9
* *                                                   * *10
*                                                          *11

Conclusion:

So, for a even numbered size its not possible to obtain a correct seriesand for a odd number, the no. of lines of series will be the exactly half the sizeEx: for the size of 9, we'll get 5 as middle number, so we get series of lines

**/

Comments