473,508 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

program using area() and perimeter() function

1 New Member
it says declaration error in this program ,what is that
and please help me

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. # define pi=22/7
  4. void area();
  5. void perimeter();
  6. void main()
  7. {
  8. area();
  9. perimeter();
  10. getch();
  11. }
  12. void area()
  13. void perimeter()
  14. {
  15. float r,pi,A,P;
  16. clrscr();
  17. printf("enter the radius :\n");
  18. scanf("%d",&r);
  19. A=pi*r*r;
  20. P=2*pi*r;
  21. printf("the area and perimeter are %f and %f",A,P);
  22. }
Feb 26 '13 #1
3 2099
Rabbit
12,516 Recognized Expert Moderator MVP
Please use code tags when posting code.

On line 12, you never finish the area function and jump right into the perimiter function.
Feb 26 '13 #2
divideby0
131 New Member
Expand|Select|Wrap|Line Numbers
  1. scanf("%d",&r);
  2.  
this is the wrong format specifier; for floats, use "%f"

Expand|Select|Wrap|Line Numbers
  1. #define PI 22/7
  2.  
I'd think you'd be getting integer division here. Promote it to a float using 22/7.0 or such

you haven't coded the function definition for area(), but tried to declare its prototype twice.

Expand|Select|Wrap|Line Numbers
  1. void area(void); // function prototype
  2.  
  3. int main()
  4. {
  5.    area(); // function call
  6.    ...
  7. }
  8.  
  9. void area(void) // function definition
  10. {
  11.    // area's definition
  12. }
Feb 26 '13 #3
donbock
2,426 Recognized Expert Top Contributor
I notice you're using float type. Most folks use double.

A better rational approximation of pi is 355/113.
22/7: error = 1.26E-03
355/113: error = 2.67E-07
Look here and here for more about approximations of pi.

Suggested C code.
Notice the constants are double's. There is no point to using float constants because the division will promote them to double's any way.
Expand|Select|Wrap|Line Numbers
  1. #define PI (355./113.)
Feb 27 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
52185
by: Jason | last post by:
I am having trouble using the CONTAINS function in sql server(enterprise manager). I am typing the following: Select * FROM mytable WHERE CONTAINS(myfield,'mystring') This returns the...
12
6045
by: Mark Constant | last post by:
I have a drop-down list now and I got it so when something is selected from the drop down list it calls a JavaScript function. I want it so the value selected from the drop-down list is sent as a...
4
2013
by: Christopher M. Lusardi | last post by:
Hello, Can I run the subject line program using CC instead of cc? I attempted to use the "-c" option and it told me things were undefined. Isn't this CC option the same as the cc -c option? ...
21
2042
by: kimimaro | last post by:
Is there anymore methods in exiting your program using pure C language other than return 0?
11
7678
by: jtagpgmr | last post by:
I am currently using the gcc compiler on a cygwin platform, I am a beginner when it comes to programming in C and want to know why anytime I run the .exe with the following code I get a...
1
2290
by: satish mullapudi | last post by:
Hi, I am using DB2 v8.2 & jdk 1.4. 1. I have a java program which returns an array which contains 1 to 5 numbers. The code: public class ArrayTest { public static final int ARRAY_SIZE = 5;...
1
1779
by: Netaro | last post by:
Well... So, i have a program. A normal program, which does something, and so.. and i have another program, which wants to run the first program.... So, there are 2 questions about that problem...
1
1920
by: faize | last post by:
I want to Write a _real time_ perl program that will take the output of tcpdump in ASCII format. Every second this program will output to screen the average number of packets as well as the average...
14
10787
by: masaniparesh | last post by:
Hi Friends, The basic issue is "To read stdin and stdout in the same program" The following program is i have wrote using thread but i figured out that stdout is working but it is not working when...
0
7226
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,...
0
7125
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...
0
7328
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,...
0
7388
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...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.