Thursday 12 October 2017

How to print diamond shape in c++?



#include<iostream>
#include<conio.h>
using namespace std;
int main(){
int k,c,num,space=1;
cout<<"How many rows do you want ? ";
cin>>num;
space=num-1;
for (k = 1; k <= num; k++)
  {
    for (c = 1; c <=space; c++)
    {
    cout<<" ";
}
      space--;
    for (c = 1; c <= 2*k-1; c++)
    {
    cout<<"*";
}
    cout<<endl;
  }
  space=1;
for(k=1;k<=num-1;k++)
{
for(c=1;c<=space;c++)
{
cout<<" ";
}
space++;
for(c=1;c<=2*(num-k)-1;c++)
{
cout<<"*";
}
cout<<endl;
}
getch();
return 0;
}



Output


No comments:

Post a Comment

Python Program to find Fabonacci

fabtab={} def fabonacci(n):     fabtab[0]=0     fabtab[1]=1     for i in range(2,n+1):         fabtab[i]=fabtab[i-1]+fabtab[i-2]         ...