### Thread: Need a program for generating the Triangular set of stars without using spaces.

Page 1 of 2 12 Last
1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
10
Rep Power
0

#### Need a program for generating the Triangular set of stars without using spaces.

I need a program for the output

*
**
***
****
*****

i.e a Triangular set of stars without using spaces in between stars...
2. Well we're not going to write it for you.

"Without using spaces"... I personally wouldn't have thought to use them in the first place. Do you have a version that does use stars? Maybe we can just help you fix that to not use them.
Or maybe you have started on something but have a problem? What's your code so far and what is the problem?
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
10
Rep Power
0

#### I have code

Ya I have a code with spaces in between star's.

Code:
```int main()
{

int c=1;
for(int i=1;i<=5;i++)
{
for(int j=i;j<5;j++)
{
cout<<" ";
}

for(int k=1;k<=c;k++)
{
if(k%2==0)
cout<<" ";
else
cout<<"*";
}
cout<<"\n";
c+=2;
}

}```
4. Code:
```if(k%2==0)
cout<<" ";
else
cout<<"*";```
Well, that second line there is where it outputs the space. Try removing it. Keep in mind you can't literally just delete the line - you need to alter the if block a bit too.
5. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
10
Rep Power
0
Originally Posted by requinix
Code:
```if(k%2==0)
cout<<" ";
else
cout<<"*";```
Well, that second line there is where it outputs the space. Try removing it. Keep in mind you can't literally just delete the line - you need to alter the if block a bit too.
Ya.. however altered, the output is not arriving... :(
6. What's your code after the changes? And what do you mean, exactly, by "not arriving"?
7. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
10
Rep Power
0
It means that I cant get any idea to get the output... Tats y asking help in this forum..
8. you can not generate such pattern without space.
if u want to make triangle without space then u should follow another pattern.

eg

*
***
*****
*******
9. Lemme tell you exactly what I did to get three different "Triangular set of stars without using spaces in between stars" outputs:
1. Created a .cpp file
2. Typed the line "#include <iostream>"
3. Typed the line "using namespace std;"
4. Copy/pasted the code from your second post

Now the changes:
5. Commented out three lines, compiled and ran, and got
Code:
```    *
***
*****
*******
*********```
6. Seeing that it was adding two stars per line when I wanted it to add one, made it only add one star per line and got
Code:
```    *
**
***
****
*****```
7. Wanted to make the triangle face right so I commented out an entire loop and got
Code:
```*
**
***
****
*****```
Now, let's try this again:
* You want the third of those outputs, right?
* What code did you try that wasn't working?
10. * You want the third of those outputs, right?
i think he want same pattern but without spaces.
and that's not possible.
11. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
10
Rep Power
0
I was asked to generate a program for this kind of pattern in the interview :(

The output I need is
*
**
***
****
*****

Simple HTML generates this output... But not C :(
12. ^^its because html has alignment option and c does not have such option.

check same pattern is gives different output.
Left:
*
**
***
****
*****

Center:
*
**
***
****
*****

Right:
*
**
***
****
*****

so it can adjust spaces by itself.
but in c we have to adjust spaces.

and we cant add half space so pattern u want without space is not possible in c.
13. Originally Posted by eramit2010
and we cant add half space so pattern u want without space is not possible in c.
Still not sure how it's impossible without spaces between the stars. All three patterns you (and I) showed don't have spaces between the stars.
14. Originally Posted by requinix
Still not sure how it's impossible without spaces between the stars. All three patterns you (and I) showed don't have spaces between the stars.

he want this pattern

*
**
***
****
*****

so if we want to make such pattern in then we need half space and i think that's not possible.

we can make such pattern with odd number of starts.
ie.
*
***
*****
*******
*********
15. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2013
Posts
84
Rep Power
6
Code:
```#include <stdio.h>

main()
{
int line, space, variable;

for(line=1; line<=9; line+=2)
{
for(space=7; space>=line; space-=2)
{
printf(" ");
}
for(variable=1; variable<=line; variable++)
{
printf("*");
}
printf("\n");
}
}```
Page 1 of 2 12 Last