#include<stdio.h>
#include<conio.h>
                 int main(){
                     float Area;
                     float r,h;
                   #define pi 3.41;
                     
                     printf("enter the radius of the  circle in centimeters\n");
                     scanf("%f",&r);
                     
                     printf("enter the height of the cilinder in centimeters\n");
                     scanf("%f",&h);
                     
                     Area=(pi*r*r)+(pi*r*h);
                     
                     printf("THE AREA OF THE CILINDER IS:%f",&Area);
                     return 0; 
                     getch();
                     }

Recommended Answers

All 4 Replies

Here is the problem

printf("THE AREA OF THE CILINDER IS:%f",&Area);

Why u use &Area ? Its a refrence type.

Use only Area to solve this....

printf("THE AREA OF THE CILINDER IS:%f",Area);

Also, pi = 3.14, not 3.41. And the area of the cylinder (note spelling)
is pi * r * r + 2 * pi * r * h.

Actually, with both endcaps, the area of a cylinder is
2 * pi * r * r + 2 * pi * r * h

Never mind executing, this code doesn't even compile.

Pay attention to your compiler's output. Errors and warnings are there for a reason; they are usually trying to tell you something important. Please post them with your questions; this will help us help you.

Problem 1:

int main() {
    float Area;
    float r, h;
#define pi 3.41;

Don't put a semicolon at the end of the definition. It will be repeated every time you use it, which means that this line...

Area = (pi * r * r) + (pi * r * h);

...is preprocessed into...

Area = (3.41; * r * r) + (3.41; * r * h);

...which doesn't do you any good.

Also, the definition of pi should go outside of main() . It will work where it is, but having it at the top of the file by your includes makes everything easier to read and understand. Also consider capitalizing the whole thing (i.e., PI )--there's nothing wrong with lowercase letters, but it is a widespread convention to put C macro definitions in all caps, so that they may easily be identified as such.

Problem 2:

printf("THE AREA OF THE CILINDER IS:%f", &Area);

Don't pass addresses to printf unless you want to print the address. You want to just use Area here.

Problem 3:

return 0;
    getch();
}

That call to getch() will never happen. A return statement should always be the very last thing in main() .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.