I am writing a recursive program to draw the lines recursively, given the
range[min,max] and number of intervals (n) between the range.
The problem is I don't know how to draw the line in point 0.375, as you see below.
Please advise! Thanks!
#include <iostream>
using namespace std;
void draw(double min, double max, int n);
int main()
{ draw(0,1,8);
}
void draw(double min, double max, int n)
{ if (n != 1)
{ double mid = (max - min)/2;
cout << mid << endl;
draw(min, mid, n/2);
}
}
The program output:
0.5
0.25
0.125
Here's the expected output:
0.5
0.25
0.125
0.375
0.75
0.625
0.875 5 6459 jr********@hotmail.com (Matt) writes: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
C has no facilities for drawing lines.
The problem is I don't know how to draw the line in point 0.375, as you see below. Please advise! Thanks!
#include <iostream>
That's not C.
The program output: 0.5 0.25 0.125
That's not a line. Those are numbers.
--
"What is appropriate for the master is not appropriate for the novice.
You must understand the Tao before transcending structure."
--The Tao of Programming
Matt <jr********@hotmail.com> wrote: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
The problem is I don't know how to draw the line in point 0.375, as you see below. Please advise! Thanks!
#include <iostream> using namespace std;
Sorry, but this a C newsgroup, there's also a C++ group in case you have
problems with C++. So let's replace this with
#include <stdio.h>
void draw(double min, double max, int n);
int main() { draw(0,1,8); }
You forgot to have main() return an int...
void draw(double min, double max, int n) { if (n != 1) { double mid = (max - min)/2;
You need to add the starting point of the interval here:
double mid = ( max - min ) / 2 + min;
(the mid-point between e.g. 4 and 5 is 4.5 and not just 0.5).
cout << mid << endl;
Sorry, this won't work in C, use instead
printf( "%f\n", mid );
draw(min, mid, n/2);
Now you're "drawing" the lower half of the interval but you forget to
also "draw" the upper half. You need an additional call:
draw( mid, max, n / 2 );
} }
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Matt wrote: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
The problem is I don't know how to draw the line in point 0.375, as you see below. Please advise! Thanks!
#include <iostream> using namespace std;
Try comp.lang.c++
--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
On 5 Oct 2003 10:44:13 -0700, jr********@hotmail.com (Matt) wrote: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
snip
Answered in alt.math. Please don't post the same message under
different subjects to multiple groups. If you must post to more than
one group, put all the group names on one message.
<<Remove the del for email>>
Matt wrote: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
Search under Bresenham's Algorithm. Can also be used to draw ellipses ;-)
--
Julian V. Noble
Professor Emeritus of Physics jv*@lessspamformother.virginia.edu
^^^^^^^^^^^^^^^^^^ http://galileo.phys.virginia.edu/~jvn/
"Science knows only one commandment: contribute to science."
-- Bertolt Brecht, "Galileo". This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Matt |
last post by:
I am writing a recursive program to draw the lines recursively, given the
range and number of intervals (n) between the range.
The problem is I don't know how to draw the line in point 0.375, as...
|
by: thomasp |
last post by:
I found the following code on MSDN to draw a line in VB2005.
Public Sub DrawLinePoint(ByVal e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create points that...
|
by: dan heskett |
last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some
custom "fields" and text layout.
Essentially it works, but I must be missing something big, conceptually,
because I...
|
by: news |
last post by:
If anyone can recommend a more appropriate newsgroup for this question?
We recently upgraded from php 4.1.2 to php 4.3.9 and ImageMagick 5.5.7
to version 6.2.5.
I have a script that creates a...
|
by: Jason Huang |
last post by:
Hi,
In my C# Windows Form, how do I draw a Line?
Thanks for help.
Jason
|
by: Rich |
last post by:
Hello,
I have a form with a panel which contains a radiobutton. When I click the
radiobutton, I invoke the Paint event of the panel using me.Invalidate. The
paint event gets called and runs...
|
by: balakrishnan.dinesh |
last post by:
Hi frnds,
Im creating function to plot line graph in javascript .
I have marked the points in graph. but what i need to do is, i want to
draw the line between those marked point, but i dont...
|
by: IvoShalev |
last post by:
Hi there,
I just want to give some sudgestions on how to draw some plain things
only using the header file <graphics.hand of course the standart
files <stdio.h<conio.h<stdlib.h>.
First of All...
|
by: zhaow |
last post by:
Hi, All
Greetings!
I want to develop as appllication that requires a line-drawing function
in the blank area between two forms. I have looked up the MSDN, it says that
a graphics object need a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |