Tuesday 13 August 2013

Fan 2

Fan 2:

In this post of shapes in c you will be able to construct the code for a fan (Part 2) in C++ using "*".

Code:

/*              Join us at
http://shapesinc.blogspot.com 
for more codes of shapes                            
*/
#include<iostream>
using namespace std;
int main()
{
cout << "Join http://shapesinc.blogspot.com for more codes of shapes\n\n";
int size;
cout<< "Enter the size of fan" << endl;
cin>>size;
for(int i=0 ; i<=size ; i++)
{
for(int j=0 ; j<i ; j++)
cout<<"  ";
for(int spaces=i ; spaces<=size ; spaces++)
{
if(i==0)
cout<<"* ";
else
if(spaces==i || spaces==size)
cout<<"* ";
else 
cout<<"  ";
}
for(int j=i ; j<size ; j++)
cout<<"  ";
for(int j=0; j<=i ; j++)
{
if(i==size)
cout<<"* ";
else 
if(j==0 || j==i)
cout<<"* ";
else 
cout<<"  ";
}
cout<<endl;
}
for(int m=0 ; m<=size ; m++)
{
for(int spaces1=m ; spaces1<=size ; spaces1++)
{
if (m==0)
cout<<"* ";
else
if(spaces1==m || spaces1==size)
cout<<"* ";
else
cout<<"  ";
}
for(int n=0; n<m ; n++)
cout<<"  ";
for(int spaces1=0 ; spaces1<=m ; spaces1++)
{
if(m==0 || m==size)
cout<<"* ";
else
if(spaces1==0 || spaces1==m)
cout<<"* ";
else 
cout<<"  ";
}
cout<<endl;
}
return 0;
}



Output:


Fan_In_Shapes_In_c




5 comments:

  1. if u give input as @#,or expect any buutons then output goes worng/somewhere

    ReplyDelete
    Replies
    1. Don't enter input other than numeric values because the size you are entering is a numerical value therefore its data type is int so, that's why you're entering a char value which is not accepted by int!!!

      Delete