Jump to content

i need help to create program!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
freestyler103

freestyler103

    Newbie

  • Members
  • Pip
  • 1 posts
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

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,720 posts
This looks like a homework assignment. What do you have so far?

#3
kia

kia

    Newbie

  • Members
  • PipPip
  • 24 posts
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

#4
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
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.

#5
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,720 posts
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:

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.