The Student Room Group
The first part is easy, no?

x=6;

for (n=x; n>0; n--)
{
for (i=n; i>0; i--)
{
printf("%s","* ");
}
prinf("%s\n","");
}


I might be missing the point, but let me know. Also, the code might not be 100% correct but it should give you the general idea.
Reply 2
secretmessages
The first part is easy, no?

yes yes,ofcourse....u made it really easy for me to understand.
and also i have run the program,its giving the exact output i asked for.
THX a lot.

BUT one thing more:what about programs like this:
1.make an empty rhombus
OR
2.
*
**
***
****
*****
****
***
**
*
secretmessages
The first part is easy, no?

x=6;

for (n=x; n>0; n--)
{
for (i=n; i>0; i--)
{
printf("%s","* ");
}
prinf("%s\n","");
}


I might be missing the point, but let me know. Also, the code might not be 100% correct but it should give you the general idea.


printf() doesn't have to take multiple arguments. printf("*"); or printf("\n"); would suffice.
Well, for the second question you asked, it's just basically what I wrote before with a bit added on in front? Right? So...
x=6;

/* this part is just the reverse of your first question
except for the very last line (of 6 *'s) */

for (n=1; n<x; n++)
{
for (j=n; i>0; i--)
{
printf("%s","* ");
}
printf("%s\n","");
}

/* this part is exactly the same as your first question */

for (n=x; n>0; n--)
{
for (i=n; i>0; i--)
{
printf("%s","* ");
}
printf("%s\n","");
}


Or as someone has said, you could just say [noparse]printf("* ")[/noparse] but I wasn't sure about that. Change the value of x depending on the length of your longest line. In your example, change it to 5.
Reply 5
Xatima
yes yes,ofcourse....u made it really easy for me to
1.make an empty rhombus
*


This should to the trick to make an empty rhombus:

#include <stdio.h>

/* The height of the rhombus, should be an odd number to look correct */
#define HEIGHT 11

int main(int argc, char** argv)
{
int l_pos; /* The current position of the left side of thr rhombus*/
int r_pos; /* The current position of the right side of the rhombus */
int i;

/* Start at the centre of the rhombus */
l_pos = r_pos = (HEIGHT / 2);

for(i = 0; i < HEIGHT; i++)
{
int j;
for(j = 0; j < r_pos; j++) /* Iterate till we get to the right hand side */
{
if(j == l_pos && l_pos != r_pos) /* If we're at the left side, print a '*' */
{
printf("*");
}
else /* Otherwise print a space for padding */
{
printf(" ");
}
}
printf("*\n"); /* Now at the right hand side, so print a '*' and move to next line */

if(i < (HEIGHT / 2)) /* Once we get to half-way down the rhombus, the sides should start closing in */
{
l_pos--;
r_pos++;
}
else
{
l_pos++;
r_pos--;
}
}
}

Reply 6
thx 4 everybody's help
i had just been stuck at one more problem:
how to print this using for loop:
-----*
----**
---***
--****
-*****
--****
---***
----**
-----*
Reply 7
Xatima
thx 4 everybody's help
i had just been stuck at one more problem:
how to print this using for loop:
-----*
----**
---***
--****
-*****
--****
---***
----**
-----*


Thats just a simplified version of my earlier answer:

#include <stdio.h>

/* The height of the shape */
#define HEIGHT 17

/* The width of the shape */
#define WIDTH (HEIGHT / 2)

int main(int argc, char** argv)
{
int i;
int pos = WIDTH; /* The '*' chars should start at the right side */
for(i = 0; i < HEIGHT; i++)
{
int j;
for(j = 0; j < WIDTH; j++)
{
if(j < pos) /* If we're before pos, print a padding space */
{
printf(" ");
}
else /* Else we've reached the start of the '*' chars */
{
printf("*");
}
}
printf("\n");

if(i < (HEIGHT / 2)) /* If we're less than half-way down the shape expand leftwards */
{
pos--;
}
else
{
pos++;
}
}
}

Reply 8
How about we don't just do his work for him.

Latest

Trending

Trending