hi
plz help me to create this program,
tell me complete code how cud i create program:
Logic :
Write a C program which will take an integer from user and make a diamond with asterisks. Using following rule:
1.Number of lines of diamond should be 2N-1.
For example if user enter 4.
Than the number of lines of diamond should be 7.
2N – 1
2*4 -1
8 – 1
7
And diamond should be like as
*
***
*****
***
*
reply me hurry
i need help to create program!
Started by freestyler103, Nov 23 2007 02:18 PM
4 replies to this topic
#1
Posted 23 November 2007 - 02:18 PM
|
|
|
#2
Posted 23 November 2007 - 09:30 PM
This looks like a homework assignment. What do you have so far?
#3
Posted 23 November 2007 - 11:29 PM
hi freestyler ! im sory but this all what i can help u with i m a Computer Science student but beginner here we go!!! but im using C++,,if it sounds ok for u,
#include<iostream>
using namespace std;
int main()
{
int i, j, N;
cout<<"Enter a number ";
cin>>N;
N = (N * 2) - 1;
for(i = 0; i <= N; i++)
{
for(j = 0; j <= i* 2; j++)
cout<<"*"<<" ";
cout<<endl;
}
return 0;
}//end
the shap ll be
*
* * *
* * * * *
hope u get a complet idea about it and some one else u ll help us complet it.
and im actualy working on it dont worry good luck
#include<iostream>
using namespace std;
int main()
{
int i, j, N;
cout<<"Enter a number ";
cin>>N;
N = (N * 2) - 1;
for(i = 0; i <= N; i++)
{
for(j = 0; j <= i* 2; j++)
cout<<"*"<<" ";
cout<<endl;
}
return 0;
}//end
the shap ll be
*
* * *
* * * * *
hope u get a complet idea about it and some one else u ll help us complet it.
and im actualy working on it dont worry good luck
#4
Posted 25 November 2007 - 11:30 PM
Create a function that outputs a line of '*' given an integer line(int num). Basically 1 would output 1 star, 2 -> 3, 3 -> 5, etc.
Then create a loop from 1 to and including N/2. Then create a loop from N/2 - 1 to and including 1 (these are separate, not nested). In each stage of the loops call call line() with the index of the loop.
Then create a loop from 1 to and including N/2. Then create a loop from N/2 - 1 to and including 1 (these are separate, not nested). In each stage of the loops call call line() with the index of the loop.
#5
Posted 26 November 2007 - 04:38 AM
You could try doing it recursively too, by creating a version that calls itself, decrementing the number of lines until it reaches zero, then returns:
You'd have to play around with the function calls a little bit though.
void line(int n)
{
if(n == 0)
return;
//do your stuff here
line(n - 1);
}
You'd have to play around with the function calls a little bit though.


Sign In
Create Account

Back to top









