English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

the pattern is
1
2 4
4 8 16
8 16 32 64
..(plz help)

2006-11-26 17:46:29 · 4 answers · asked by sweety 2 in Computers & Internet Programming & Design

4 answers

I am assuming that all you want is that simple pattern drawn.

For a predefined size of the triangle LINELIMIT:

int main() {
int head = 1. prev; line = 0, col = 0;

for (line = 0; line < LINELIMIT; line++) {
prev = head;
for (col = 0; col < line; col++) {
printf("%d ", prev);
prev *= 2;
}

printf("\n");
head *= 2;
}

return 0;
};

2006-11-26 18:12:22 · answer #1 · answered by jhskim 2 · 0 0

If we want a main that doesn't give compile warnings, though I haven't tried it...

int main(int argc, char **argv)
{
(void)argc;
(void)argv;

unsigned firstVal = 1;
int i = 0;
int j = 0;
for(i=0; i<16;i++)
{
unsigned prVal = firstVal;
for(j=0;j<=i; j++)
{
printf("%d ",prVal);
prVal *= 2;
}
printf("\n");
firstVal *= 2;
}

return 0;

}

I think that should do it. Of course if you really wat a triangle you are going to have to do something inventive with the format and that method isn't going to work for the 17th row unless you switch to unsigned longs. I could have used << 1 instead of *=2, it would have been more appropriate for the problem, perhaps.

Homework? So I haven't done you any favors by giving you an answer.

2006-11-26 18:21:33 · answer #2 · answered by Chris H 6 · 0 0

that's C and improvable even though it truly works and also try to be able to make sure it out: #contain int substantial(){ int i, j; j=0; for (i=0;i<5;i++) { even as (j

2016-11-29 20:07:49 · answer #3 · answered by laranjeira 4 · 0 0

a=1 ;
for(i=1; i<=10; i++)
{
for(j=1; j<=i; j++)
{
printf("%d ", a) ;
a = a+a ;
}
}


:)

2006-11-26 18:04:18 · answer #4 · answered by Santosh 2 · 0 1

fedest.com, questions and answers