By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

Histogram help

P: n/a
hi all ;

-------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
main()
{

int gd = DETECT, gm, kod, i,x,y,a,x1;
initgraph(&gd, &gm, "C:\Dev-Cpp\bin");
kod graphresult();

x=getmaxx();
y=getmaxy();
a=x/12; x1=10;

randomize();
line(0,0,0,y);
line(0,y,x,y);

for (i=0; i<6; i++)
{
setfillstyle(i,random(getmaxcolor()));
bar3d(x1,random(y)+20, x1+a, y-1,a/2,1);
x1=x1+a*2;
}
getch();
closegraph();
}

----------------------------------------------------------------------------------------------------------------------

or

------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>

int main(void)
{
int i, j, mark[] = {7,6,9,4,7,7,5,10,8,6,5};
for ( i = 0; i < sizeof mark / sizeof *mark; ++i )
{
printf("%2d|", i + 1);
for ( j = 0; j < mark[i]; ++j )
{
fputs(" ", stdout);
}
puts("*");
}
puts(" +----------------------");
puts(" 0 1 2 3 4 5 6 7 8 9 10");
return 0;
}

---------------------------------------------------------------------------------------------------------------
First one is a 3d bar graphics and second is a histogram graphic,
How can I do first or second graphics for the numbers that I'll enter
randomly ??

Jun 13 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a

"DeLiLlaH" <nk*****@mynet.comwrote in message
news:11**********************@g37g2000prf.googlegr oups.com...
hi all ;

-------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
main()
{

int gd = DETECT, gm, kod, i,x,y,a,x1;
initgraph(&gd, &gm, "C:\Dev-Cpp\bin");
kod graphresult();

x=getmaxx();
y=getmaxy();
a=x/12; x1=10;

randomize();
line(0,0,0,y);
line(0,y,x,y);

for (i=0; i<6; i++)
{
setfillstyle(i,random(getmaxcolor()));
bar3d(x1,random(y)+20, x1+a, y-1,a/2,1);
x1=x1+a*2;
}
getch();
closegraph();
}

----------------------------------------------------------------------------------------------------------------------

or

------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>

int main(void)
{
int i, j, mark[] = {7,6,9,4,7,7,5,10,8,6,5};
for ( i = 0; i < sizeof mark / sizeof *mark; ++i )
{
printf("%2d|", i + 1);
for ( j = 0; j < mark[i]; ++j )
{
fputs(" ", stdout);
}
puts("*");
}
puts(" +----------------------");
puts(" 0 1 2 3 4 5 6 7 8 9 10");
return 0;
}

---------------------------------------------------------------------------------------------------------------
First one is a 3d bar graphics and second is a histogram graphic,
How can I do first or second graphics for the numbers that I'll enter
randomly ??
The api, which is not standard C, seems to be basiclaly a wrapper for this
function

bar3d(x1,random(y)+20, x1+a, y-1,a/2,1);

The first four parameters look like x, y coordinates of the corners, the
other parameerts are preasumably colour, line thickness, and so on, but I
cannot quite decipher.

However we can adjust the call easily enough.

int randinput[6];

/* enter the random numbers in a loop using scanf() */
for(i=0;i<6;i++)
scanf("%d\n" &randinput[i]);

for(i=0;i<6;i++)
bar3d(i*10, randinput[i], i*10+10, 1, something, somethingelse);

with any luck this will place a bar where you want it. You might have to
fiddle with the values - I've assumed you want 10 pixel wide bars going from
1 to the random number. Also the two extra parameters you'll have to look
up - not being familiar with the call I can't work everything out from one
code sample.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 13 '07 #2

P: n/a
DeLiLlaH wrote:
>
hi all ;

--------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
main()
Errors so far: No such std include files as <conio.hor
<graphics.h>. main returns an int, say so. If main takes no
arguments, say so with "int main(void)". c.l.c deals with the
standard C language as described in the various C standards. Other
things are off-topic.

Also please limit your line length to 72 (but 67 is better).

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 14 '07 #3

P: n/a
CBFalconer said:
DeLiLlaH wrote:
>>
hi all ;

--------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
main()

Errors so far: No such std include files as <conio.hor
<graphics.h>.
They're not errors. They merely render the program non-portable.
main returns an int, say so.
He did, using the "implicit int" rule. Not good style, perhaps, but
*not* an error.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 14 '07 #4

P: n/a
On 14 Jun 2007 at 1:51, CBFalconer wrote:
Also please limit your line length to 72 (but 67 is better).

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com
Please limit your signature block to 1, not 2, signatures, of 4 lines
(but 0 is better).

Jun 14 '07 #5

P: n/a
On Jun 14, 7:04 pm, Richard Heathfield <r...@see.sig.invalidwrote:
CBFalconer said:
Errors so far: No such std include files as <conio.hor
<graphics.h>.

They're not errors. They merely render the program non-portable.
Well, conforming compilers could report an error on
those lines, and refuse to compile the code. Perhaps
that is what CBFalconer meant.
Jun 15 '07 #6

P: n/a
Old Wolf said:
On Jun 14, 7:04 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>CBFalconer said:
Errors so far: No such std include files as <conio.hor
<graphics.h>.

They're not errors. They merely render the program non-portable.

Well, conforming compilers could report an error on
those lines, and refuse to compile the code. Perhaps
that is what CBFalconer meant.
Perhaps. I agree that discussions of extensions would render this group
unusable, but I wish we could say so without suggesting that
non-portable code presented here is somehow /wrong/. What's wrong is
not the code (necessarily) but the choice of newsgroup in which to post
it.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 15 '07 #7

P: n/a
On Fri, 15 Jun 2007 09:19:11 +0000, in comp.lang.c , Richard
Heathfield <rj*@see.sig.invalidwrote:
>Perhaps. I agree that discussions of extensions would render this group
unusable, but I wish we could say so without suggesting that
non-portable code presented here is somehow /wrong/. What's wrong is
not the code (necessarily) but the choice of newsgroup in which to post
it.
<mode=mild sarcasm>
Richard has apparently been travelling on the Road to Damascus...
</mode>
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 15 '07 #8

P: n/a

"CBFalconer" <cb********@yahoo.comha scritto nel messaggio
news:46***************@yahoo.com...
DeLiLlaH wrote:
>>
hi all ;

--------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
main()

Errors so far: No such std include files as <conio.hor
<graphics.h>. main returns an int, say so. If main takes no
arguments, say so with "int main(void)". c.l.c deals with the
standard C language as described in the various C standards. Other
things are off-topic.
6.10.2:
A preprocessing directive of the form
# include <h-char-sequencenew-line
searches a sequence of implementation-defined places for a header identified
uniquely by
the specified sequence between the < and delimiters, and causes the
replacement of that
directive by the entire contents of the header. How the places are specified
or the header
identified is implementation-defined.

One should use <for headers provided by the implementation,
wheter they're standard or not, and "" for the ones he wrote himself. The
only "error" is assuming that people in comp.lang.c are familiar with
something which is not on topic here.
Jun 15 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.