In: Computer Science
a) Write a function drawShape() that accepts a parameter n, and:
b) What is the time complexity of the drawShape() function you created?
C++ language with for loop
#include <iostream>
using namespace std;
void drawShape(){
int n;
cout<<"Enter the Parameter N"<<endl;
cin>>n;
if(n%2!=0){
cout<<"The Number you entered is ODD"<<endl;
int c, k, count=1;
count=n-1;
for (k=1; k<=n; k++)
{
for(c=1; c<=count; c++)
{
cout<<" ";
}
count--;
for(c=1; c<=(2*k-1); c++)
{
cout<<"*";
}
cout<<"\n";
}
count=1;
for(k=1; k<=(n-1); k++)
{
for(c=1; c<=count; c++)
{
cout<<" ";
}
count++;
for(c=1 ; c<=(2*(n-k)-1); c++)
{
cout<<"*";
}
cout<<"\n";
}
// getch();
}
else if(n%2==0){
cout<<"The Number you entered is EVEN"<<endl;
int i,j,k=9,s=0,l;
// clrscr();
for(i=0;i<5;i++,k-=2,s+=1)
{
for(l=s;l>=0;l--)
cout<<' ';
for(j=k;j>0;j--)
cout<<"#";
cout<<endl;
}
for(i=0;i<5;i++,k-=2,s-=1)
{
for(l=s-1;l>=0;l--)
cout<<' ';
for(j=k;j<0;j++)
cout<<"#";
cout<<endl;
}
// getch();
}
}
int main() {
drawShape();
return 0;
}
PLEASE GIVE A THUMBS UP!!!!!!!!!!!