for-loop ..help!

somali.cc's Avatar, Join Date: Aug 2010
Go4Expert Member
Hello all, pls guide me how to write a C-program to generate the following output:

*
**
***
****
*****
somali.cc's Avatar, Join Date: Aug 2010
Go4Expert Member
sorry y aar....I want it typed from right to left....
*
**
***
****
*****
somali.cc's Avatar, Join Date: Aug 2010
Go4Expert Member
again same thing...how to delete a post???
jimblumberg's Avatar
Ambitious contributor
So what have you tried? Post the code that is causing you the problems. Also post any error messages you receive from compiling your code.


Jim
virxen's Avatar, Join Date: Nov 2009
Pro contributor
do you mean like this?
Quote:
*
**
***
****
*****
somali.cc's Avatar, Join Date: Aug 2010
Go4Expert Member
@ Virxen

Yes u have got dat diagram right.

@Jim & @ Virxen

I am not being able to write a program in C dat will give me the output (as Virxen's diagram).
virxen's Avatar, Join Date: Nov 2009
Pro contributor
hints
=========
-your output must have 5 lines (maybe a for from 1 to 5?)

-the first time you print 4 spaces and one star=5 characters (maybe a second or third for?)
.....
the fifth time no spaces and 5 stars=5 characters


start writing code and post your attempts here to help you.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Here's one that will do the trick:
Code:
void test29()
{
	char *ch=" ****************";
	for (int i=1; i<ch[0]; i++)
	{
		for (int j=ch[0]/2; j; j>>=1)
		{
			putchar(ch[i&j]);
		}
		i<<=putchar('\n')/'\n';
	}
}
Hope you get a good mark!
shabbir like this
somali.cc's Avatar, Join Date: Aug 2010
Go4Expert Member
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=5;i++)
{
for(j=5-i;j>=1;j--)
printf(" ");

for(k=1;k<=i;k++)
printf("*");

printf("\n");
}
getch();
}
somali.cc's Avatar, Join Date: Aug 2010
Go4Expert Member
I am absolutely new to C-programming. Just started with for-loop