473,749 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to compile this ( trying to find roots of a bisection)

*************** *************** *************** *************** *************** *************** *************** **

#include<stdio. h>
#include<conio. h>
#include<math.h >

void main()
{
double a,b,c,fa,fb,fc, err;
int count;
clrscr();
printf("\n enter value for %lf",a);
scanf("%lf",&a) ;
printf("\n enter value for %lf",b);
scanf("%lf",&b) ;
err = exp(-6);
printf("\n value of %lf",err);
while(fabs(a-b)<=err)
{
fa=2-(3*sin(a)*exp(a ));
printf("\n the value of %lf",fa);
fb=2-(3*sin(b)*exp(b ));
printf("\n the value of %lf",fb);
c=(a+b)/2;
fc=(fa+fb)/2;
If (fa!=0)
{
If ((fa>0)&&(fb>0) )
a = c;
else
b = c;
}
Else
{
printf("\n the value of fa does not exist, proceed with fb");
}

If (fb != 0)
{
If (fb > 0)
If (fc > 0)
b = c;
else
a = c;
}
Else
{
printf ("\n fa,fb do not exist, cannot proceed");
}
count++
}
printf("\n the value of %lf",a);
printf("\n the value of %lf",b);
printf("\n the value of %d",count);
}

*************** *************** *************** *************** *************** *************** *************** *

Feb 25 '06 #1
18 2066
anand schrieb:
*************** *************** *************** *************** *************** *************** *************** ** Please state your problem in the message text, too.
BTW: "need to compile this ( trying to find roots of a bisection)"
is not very helpful.
#include<stdio. h>
#include<conio. h>
This is not a standard C header, so I will ignore it and
all functions which have no prototype in one of the other
included headers.
#include<math.h >

void main()
This is the wrong type for main().
Write either
int main (void)
or
int main (int argc, char **argv)
Read
http://c-faq.com/ansi/index.html
Question 11.12a through 11.15 {
double a,b,c,fa,fb,fc, err;
int count;
clrscr();
Unknown function.
printf("\n enter value for %lf",a);
In C89, using %lf in printf() leads to undefined behaviour.
http://c-faq.com/stdio/scanfvsprintf.html
Even if you used %f, %e, %g, you still are passing an
uninitialized variable as argument.
So you luck out in every possible way. Your program is already
dead.
scanf("%lf",&a) ;
Note: 1)If you want the preceding printf() to be printed out,
either terminate it by '\n' or use fflush(stdout) -- otherwise,
the output prompt might show up after the input it should
precede.
2) scanf() is not really good for interactive input.
Read the comp.lang.c FAQ on this:
http://c-faq.com/stdio/scanfhang.html
http://c-faq.com/stdio/scanfinterlace.html
printf("\n enter value for %lf",b);
scanf("%lf",&b) ;
dito.
err = exp(-6);
printf("\n value of %lf",err);
while(fabs(a-b)<=err)
{
fa=2-(3*sin(a)*exp(a ));
printf("\n the value of %lf",fa);
fb=2-(3*sin(b)*exp(b ));
printf("\n the value of %lf",fb);
c=(a+b)/2;
fc=(fa+fb)/2;
If (fa!=0)
Here you are not even trying anymore.
C is a case sensitive language, so you have to stay
with "if", "else", ... {
If ((fa>0)&&(fb>0) )
a = c;
else
b = c;
}
Else
{
printf("\n the value of fa does not exist, proceed with fb");
}

If (fb != 0)
{
If (fb > 0)
If (fc > 0)
b = c;
else
a = c;
}
Else
{
printf ("\n fa,fb do not exist, cannot proceed");
}
count++
}
printf("\n the value of %lf",a);
printf("\n the value of %lf",b);
printf("\n the value of %d",count);
return 0; }


I did not look at the algorithm or at the loop contents.
Fix the above first and describe further problems.

Reading the whole comp.lang.c FAQ may help you avoid other
errors.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Feb 26 '06 #2
anand wrote in the subject line "need to compile this ( trying to find
roots of a bisection)" followed by illiterate garbage claiming to be C
[mercifully snipped].

No, you need
1) To open your C text to page 1 and start over and
2) learn to not put an important part of your post in the headers, where
many people will ignore it.
Feb 26 '06 #3
anand wrote:

*************** *************** *************** *************** *************** *************** *************** **

#include<stdio. h>
#include<conio. h>
#include<math.h >

void main()
{
double a,b,c,fa,fb,fc, err;
int count;
clrscr();


It won't compile. There is no such header file as conio.h. There
is no such routine as clrscr(). main returns an int, not void. I
did not look further.

At least in C. If you are using some other language with vague
similarities to C you need to use a newsgroup that deals with that
language. This is not it.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>

Feb 26 '06 #4
"anand" writes:

*************** *************** *************** *************** *************** *************** *************** **

#include<stdio. h>
#include<conio. h>
#include<math.h >

void main()
{
double a,b,c,fa,fb,fc, err;
int count;
clrscr();
printf("\n enter value for %lf",a);
scanf("%lf",&a) ;
printf("\n enter value for %lf",b);
scanf("%lf",&b) ;
err = exp(-6);
printf("\n value of %lf",err);
while(fabs(a-b)<=err)
{
fa=2-(3*sin(a)*exp(a ));
printf("\n the value of %lf",fa);
fb=2-(3*sin(b)*exp(b ));
printf("\n the value of %lf",fb);
c=(a+b)/2;
fc=(fa+fb)/2;
If (fa!=0)


Use cut and paste, not retype. There is no reason in the world to expect
that to compile. The magic word is "if", not "If". If you repost tell us
what happens. Did it compile? Don't imply something or other by saying
"Need to compile".

<snip>
Feb 26 '06 #5
CBFalconer <cb********@yah oo.com> writes:
anand wrote:

[...]
#include<stdio. h>
#include<conio. h>
#include<math.h >

void main()
{
double a,b,c,fa,fb,fc, err;
int count;
clrscr();


It won't compile. There is no such header file as conio.h. There
is no such routine as clrscr(). main returns an int, not void. I
did not look further.

At least in C. If you are using some other language with vague
similarities to C you need to use a newsgroup that deals with that
language. This is not it.


As I'm sure you know, there is a header file called conio.h and a
function called clrscr() *on some systems*. (Of course, there's no
reason to use either in a program that just performs some mathematical
operations.)

Declaring "void main()" makes it incorrect C, not non-C.

The use of system-specific headers and functions makes the program
non-portable (and off-topic here); it doesn't make it non-C. One of
C's greatest assets is its ability to support system-specific
extensions.

What makes the program non-C is its use of "Else" and "If" rather than
"else" and "if".

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 26 '06 #6
As far as I could see, you may be using borland C or similar compiler
for DOS or windows environments because of the conio.h header file.

Your code will not compile because of some "If" and "Else" statemens.
You can't use capital letters on them. About your main function, there
is nothing wrong with it. It can have one of the forms:

void main(void)
int main(void)
int main(int argc, char **argv)
int main(int argc, char *argv[])
and some extensions supports the form
int main(int argc, char **argv, char **envp)

Next time you post something here, try to be more explicit about the
problems you are going through.

Feb 26 '06 #7
Ronaldão wrote:

As far as I could see, you may be using borland C or similar
compiler for DOS or windows environments because of the conio.h
header file.

Your code will not compile because of some "If" and "Else"
statemens. You can't use capital letters on them. About your main
function, there is nothing wrong with it. It can have one of the
forms:

void main(void)
No, this is not allowed. main always returns int.
int main(void)
int main(int argc, char **argv)
int main(int argc, char *argv[])
and some extensions supports the form
int main(int argc, char **argv, char **envp)
This is not specified in the C standard. Do not assume it. See
the standard routines getenv and putenv.

Next time you post something here, try to be more explicit about
the problems you are going through.


The next time you post here try to be more accurate in your
answers.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>

Feb 26 '06 #8
On 2006-02-26, CBFalconer <cb********@yah oo.com> wrote:
Ronaldão wrote:
and some extensions supports the form
int main(int argc, char **argv, char **envp)


This is not specified in the C standard. Do not assume it. See
the standard routines getenv and putenv.


putenv is only _barely_ more standard [in that it's defined in _a_
standard] than envp, and isn't likely to be supported on any
implementations where envp is not. He _did_ say it was an extension.
Feb 26 '06 #9
Keith Thompson <ks***@mib.or g> writes:
CBFalconer <cb********@yah oo.com> writes: Declaring "void main()" makes it incorrect C, not non-C.
Well, nowadays, it makes it non-portable C, not incorrect C. :-)

'course, depending on your definition for "incorrect C", the two may
overlap... :-)
What makes the program non-C is its use of "Else" and "If" rather than
"else" and "if".


I suspect the OP was used to MS Visual Basic or somesuch.
Feb 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1811
by: EasyRider41 | last post by:
I am trying to merge to scripting samples I for on a source code web site and having limited luck. Then first one is called Zebra Tables witch colors alternate rows of a table to look beter. The second is a rule code that highlights the row you are currently moused over. Both are making use of CSS style sheet to do all of their formating. My problem is that the rollover is changing the text color but not the color of the row background as...
0
1288
by: Raymond L. Buvel | last post by:
If you are using the root finder in Numeric, and are having problems, check out the root finder in the ratfun module. My testing indicates that it will give the exact roots of a Wilkinson polynomial of degree 100. For more information see http://calcrpnpy.sourceforge.net/ratfun.html
3
2370
by: MatGyver | last post by:
I am going nuts trying to figure this out, any help will be appreciated. I have an existing table called "Parts". And in this table I have the following columns: "ID" "Part Number" "Part Description" "Part Cost" I am trying to build an order form that will have "Part Number" and "Part Cost" both on the form and in that forms specific table.
2
2036
by: Derek Jones | last post by:
I am currently working on an application for our Business Office to easily search for new budget codes that we have to establish due to an administrative system conversion we are currently undergoing. They would like to be able to find a new code via searching by old code or searching by the object name. I have the search by old code form done exactly the way they want it. For the search by object name form, I have it set up with a...
1
1127
by: TiggerBaby505 | last post by:
ok have u ever been on a website someone makes and they have these really cool cursors that have some glitter or bouncy balls followin them? well i need help to find out where to go and look for them... i really want to be able to download or make them for my site... can anyone plz help me? TiggerBaby505
1
1430
by: Learner | last post by:
HI Friends, I am brand new to creating Crystal reports. But overcomed a lot of problems and so far happy what i could accomplish, calling a stored proc with a parameter in it. And i can see the results in the Crystal Reports in the front. Our client would like to be exported to a .rtf file when an Export button is clicked on. I have no problem exporting it to(actually there was a problem converting to .pdf or Excel, it goes to the...
6
1828
by: chris_fieldhouse | last post by:
Hi, I have a script for processing emails, The script finds email sent to a particular alias, grabs the body text of the email and stores it into a database. Problem is that certain character like '_' sometimes get stored as =5F, and some email clients seem to add in =0D encoded characters. I store the text in an Mysql database, and depending on the message
14
5524
by: mistral | last post by:
Need compile python code, source is in html and starts with parameters: #!/bin/sh - "exec" "python" "-O" "$0" "$@" I have installed ActivePython for windows.
0
991
by: gsuns82 | last post by:
Hi all, I am using Pattern.compile("<option(*)") in order fetch the following value <option value="new-new">Neuf</option>. Can any one suggest me a regex which will fetch the "<option value="new-new">Neuf</option>" value from the response form.??? Note:I got "value=" as a result for the regex Pattern.compile("<option(*)"). Thanks&Regards,
0
8996
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6800
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.