need coding within 12 hours...:(

Pages: 12
*****
****
***
**
*

*****
1****
11***
111**
1111*
I want coding in c++ which shows above output... please delete 1
Last edited on
please reply
1
2
3
4
5
#include <iostream>
int main()
{
	std::cout << "*****\n****\n***\n**\n*\n\n*****\n ****\n  ***\n   **\n    *\n";
}
Well played...
No Sir using loop get out put
#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???
Why don't you test it?
Last edited on
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
HOMEMADE DYNAMIC MEMORY ALLOCATION
FROM DA C PROGRAMMING LANGUAGE
SHOUTOUTS TO MA BOY KERNIGHAN, RIP

I second the "SHOUTOUT".
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
Yes and dynamically allocating each star, one of my better pieces of code :)
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.
You're... joking right?
no its probably because they googled their assignment and saw your solution and copied it as their own.
@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...
@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.
@ascii
wait, so that code is crap?
Sorry if this sounds slightly unorthodox, but ROFL! :D Nice one, ascii!!! Respect...
Pages: 12