-
a question
this is the output
*
**
***
****
*****
******
*******
********
*********
**********
and i want to right a programme to print this output by using for loop and one printf statement printf( "*" )and it should print the whole pattern ,please can you help me
the stars are right justified opposite of the picture given means not left justified
-
A nested for loop will do. The first one looping as many times as the pyramid is high, and the second (inner) one starts with 1 loop, then increasing by 1 per outer loop.
-
but how it wouldn't be right justified how could i make it?
-
Print the string " " (a space) before the stars (Height - i) times, where Height is the height of the pyramid (nr of rows) and i is the current line number (when looping).
-
Make two loops inside the large one, one that counts out totalLines-currentLine spaces, and another that counts out currentLine '*'s.
~Inquirer
[EDIT]
Beaten again...
[/EDIT]
-
im surprised no one said anything about him doing his own homework.
-
No one is giving away the farm here.
The code is still up to kuwait.
It's something of a judgement call, although I do see your point. Rather a fine line sometimes. ;)
-Skipper
-
i know how to do it my problem is how to make it right justified
for(i=1;i<=10;i++){
for(j=1;j<=i;j++)
printf("*");
printf("\n");
}
i did this but it wouldn't be right justified how can i do it what should i use pleas can u help?
And thanx for all
-
You'll need to know the screen size before justifying it to the right.
-
sorry
the picture which i put is wrong it is right justified i only want to put blanks 9 blanks before the first star
8blanks befor the 2nd two stars and so on
how to do this
-
Code:
for(int i=1; i<=10; i++)
{
for(int k=10-i; k>0; k--)
{
printf(" ");
}
for(j=1; j<=i; j++)
{
printf("*");
printf("\n");
}
}
You want 10-i spaces before each line of stars right?
so just print 10-i spaces. Meaning, print a space 10-i times.
-
it doesn't work sorry
i tried it
i also need blanks before the columns not just the rows i want a triangle of stars to appear
thanx for ur help
-
Those triangles are boring, give your teacher something more interesting and you may get some extra credit. ;)
Code:
#include <iostream>
const int N = 16;
int main ()
{
for ( int n = 0; n < N; ++n ) {
for ( int k = 0; k <= n; ++k )
std::cout.put ( ( ~n & k ) ? ' ' : '*' );
std::cout.put ( '\n' );
}
std::cin.get();
}
-Prelude
-
You can use the setw() fxn in the header file <iomanip> this will let you have a right-justified display.
or you can add another for loop to your nested loops with a decrementing counter that prints out space ' ' characters.
-
hi there
i'm not able to answer it this way it requires to solve it by using for loop and using just <stdio.h> libary