need coding within 12 hours...:(

Pages: 12
Nov 24, 2011 at 4:43pm
*****
****
***
**
*

*****
1****
11***
111**
1111*
I want coding in c++ which shows above output... please delete 1
Last edited on Nov 24, 2011 at 5:01pm
Nov 24, 2011 at 4:57pm
please reply
Nov 24, 2011 at 5:10pm
1
2
3
4
5
#include <iostream>
int main()
{
	std::cout << "*****\n****\n***\n**\n*\n\n*****\n ****\n  ***\n   **\n    *\n";
}
Nov 24, 2011 at 5:11pm
Well played...
Nov 24, 2011 at 5:32pm
No Sir using loop get out put
Nov 24, 2011 at 6:17pm
#include <constream.h>
void main (void)
{
int outer,inner;
clrscr();
for(outer=6;outer>1;outer--)
{

for(inner=2;inner<=outer;inner++)
{

cout<<"*";
}
cout<<"\n";
}
for(outer=1;outer<6;outer++)
{

for(inner=1;inner<=outer;inner++)
{
cout<<"*";
}
cout<<"\n";

}

getch();
}


Is it right???
Nov 24, 2011 at 7:36pm
Why don't you test it?
Nov 24, 2011 at 7:43pm
Last edited on Nov 24, 2011 at 7:47pm
Nov 24, 2011 at 7:58pm
Mine's slightly more elegant than the others posted. I'm sure your professor will be quite pleased with your progress :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#if SYSTEM == MSDOS
     #define MAXSTARS 5 
#endif

int printstars(int max, int eofval, char *star);
void copy(int *x, int *i);
char* alloc(int n);
void afree(char *p);


int main(int argc, char *argv[]) {
    int i, c;
    char star;
    for(i = 0; i < MAXSTARS; i++)
	c = '\0';
    c = EOF;
    int max;
    copy(&max, &i);
    printstars(max, c, &star);
    return 0;
}

void copy(int *x, int *i) {
    *x = *i;
}

int printstars(int max, int eofval, char *star) {
    int temp = max;
    while(max != 0 && max != eofval) {
	star = alloc(1);
	*star = '*';
	int i;
	for(i = 0; i < max; ++i) 
	    printf("%c", *star);
	--max;
	afree(star);
	printf("\n");
    }
    int i;
    for(i = 0; i <= 0x103F; ++i) /* copy a lot of times to mke sure it work */
	max = temp;
    printf("\n");
    max &= max;
    max = ~max;			/* lolbitstuff */
    max = ~max;
    temp = max;			/* copy again for goodz luck */
    while(max != 0 && max != eofval) {
	star = alloc(1);
	*star = '*';
	int i = max;
	while(i++ < temp)
	    printf(" ");
	for(i = 0; i < max; ++i)
	    printf("%c", *star);
	--max;
	afree(star);
	printf("\n");
    }
    return ~max;
}

/* HOMEMADE DYNAMIC MEMORY ALLOCATION */
/* FROM DA C PROGRAMMING LANGUAGE */
/* SHOUTOUTS TO MA BOY KERNIGHAN, RIP */
#define ALLOCSIZE 1000
static char allocbuf[ALLOCSIZE];
static char *allocp = allocbuf;

char* alloc(int n) {
    if(allocbuf+ALLOCSIZE-allocp >= n) {
	allocp += n;
	return allocp - n;
    }
    else 
	return 0;
}

void afree(char *p) {
    if(p >= allocbuf && p < allocbuf + ALLOCSIZE)
	allocp = p;
    return;
}

It is C, but for intense problems like this you need the extra efficiency. I'm sure your professor will understand.

If you have any questions I'm happy to answer them :)
Last edited on Nov 24, 2011 at 8:02pm
Nov 24, 2011 at 8:09pm
HOMEMADE DYNAMIC MEMORY ALLOCATION
FROM DA C PROGRAMMING LANGUAGE
SHOUTOUTS TO MA BOY KERNIGHAN, RIP

I second the "SHOUTOUT".
Nov 25, 2011 at 3:32pm
That's incredible!!! What code. That'd get an A+ for sure.

Copying something 0x103f times to make sure it works? Brilliant.

Edit: I just compiled it, it works as advertised!
Last edited on Nov 25, 2011 at 5:00pm
Nov 25, 2011 at 4:40pm
Yes and dynamically allocating each star, one of my better pieces of code :)
Nov 25, 2011 at 4:52pm
ascii, I must ask you to stop posting full solutions. As a tutor myself, I can say that it is virtually impossible for me to check whether my students made their homework myself or got it from somewhere else.

Incidentally, the code you provided is the exact solution most of my students come up with when given this assignment, because it is the most logical way to do it.
Nov 25, 2011 at 6:24pm
You're... joking right?
Nov 25, 2011 at 6:46pm
no its probably because they googled their assignment and saw your solution and copied it as their own.
Nov 25, 2011 at 6:55pm
Nov 25, 2011 at 7:09pm
@TheMassiveChipmunk what does that mean? That was just an excerpt from The C Programming Language.

@wtf, I purposely made that code as obfuscated, inefficient and stupid as I could to encourage people not too copy it, so to anyone who did, good luck explaining it to their professor I guess...
Nov 25, 2011 at 7:11pm
@ascii Sorry I just wanted to show you other results with some of the same code. I didn't know that it was an excerpt.
Nov 25, 2011 at 7:37pm
@ascii
wait, so that code is crap?
Nov 25, 2011 at 7:44pm
Sorry if this sounds slightly unorthodox, but ROFL! :D Nice one, ascii!!! Respect...
Pages: 12