Inline Code Example Herehi i want to print the diamond as shown bellow,which is generic i mean depend on the user input.the following output is for "5",

Heading Here

           1
          232
         34543 
        4567654 
       567898765 
        4567654
         34543
          232
           1

Okay. Do you know how to use a for loop?

Is this homework? If it is you should read this post.

We only give homework help to those that try. Do you have any code so far? Do you know how to use for loops?

#include<iostream>
using namespace std;
int main()
{
    for(int i=0;i<13;i++)
    {
        cout<<"*";
        if(i==0 || i==12 ||i==9)
        {
            for(int j=0;j<10;j++)
            {
                if(i==9 && j==0)
                {
                    cout<<" ";
                }
                else
                    cout<<"*";
            }
        }
        else if(i==10)
        {
            cout<<" "; 
            cout<<"*";
            for(int j=0;j<7;j++)
            {
                cout<<" ";
            }
            cout<<"*";
        }
        else if((i==1 || i==2 || i==11))
        {
            for(int j=0;j<9;j++)
                cout<<" ";
            cout<<"*";
        }
        cout<<'\n';
    }
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.