Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   for-loop ..help! (http://www.go4expert.com/forums/for-loop-help-t23076/)

somali.cc 23Aug2010 13:21

for-loop ..help!
 
Hello all, pls guide me how to write a C-program to generate the following output:

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

somali.cc 23Aug2010 13:26

Re: for-loop ..help!
 
sorry y aar....I want it typed from right to left....
*
**
***
****
*****

somali.cc 23Aug2010 13:27

Re: for-loop ..help!
 
again same thing...how to delete a post???

jimblumberg 24Aug2010 01:49

Re: for-loop ..help!
 
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 24Aug2010 02:49

Re: for-loop ..help!
 
do you mean like this?
Quote:

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


somali.cc 24Aug2010 09:33

Re: for-loop ..help!
 
@ 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 24Aug2010 13:24

Re: for-loop ..help!
 
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 24Aug2010 13:32

Re: for-loop ..help!
 
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!

somali.cc 24Aug2010 22:40

Re: for-loop ..help!
 
#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 24Aug2010 22:43

Re: for-loop ..help!
 
I am absolutely new to C-programming. Just started with for-loop


All times are GMT +5.5. The time now is 23:56.