Here is one of my beginning projects last year :
const int row = 1;
for(int i = 0; i < row; i++)
{
for(int j = row-i; j ; j--)
cout<<" ";
for(int k = i*2; k >= 0; k--)
cout<<"*";
cout<<endl;
}
for(int i = row; i >= 0; i--)
{
for(int j = i; j < row; j++)
cout<<" ";
for(int k = i*2; k >= 0; k--)
cout<<"*";
cout<<endl;
}
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
Well, Its quite simple, Use the same formula that you have in the existing code, But just change all the instances of '5' with a variable.
For Eg:
for(i=1; i<=5; i++)
This could be something like/
int len=5;
for (i=1;i<=len;i++)
Now you will then need to further need to take in the value of len from the user,.
Check if it lies between 1 - 19 and then look if it is odd. with the % operator. .
Then if all those conditions are satisfied. continue with the for loops or display an message stating that you have entered a wrong value or . Put a default value for len and continue.poncho4all Your effort of posting down the code is much appreciated, However This forum tends to provide paths to the solution, But not to the solution itself. Read the rule Here. .
Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131
Well,
To get this program running in C, there are only a few minor editions that have to be done.
Firstly,
header must be replaced with the standard 'C' Header file 'stdio.h'
Next consider all cout<< statements as printf statements, Note that cout <> refers to scanf()..
Now since you have a brief Idea. Try experimenting and get to the solution.
And maybe from the next-time, Start a new thread instead of Continuing this one.
Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131