Question
write a c programming

Write a program that will calculate the perimeter, area and volume of a is is entered by the user. Your program will display
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

typedef struct{

    float radius;

    float area;

    float perimeter;

    float volume;

} figure;

int main()

{

    // create a variable of type figure

    figure x;

   

    printf("Enter radius : ");

   

    // get user input

    scanf("%f", &x.radius);

   

    // calculate perimeter

    x.perimeter = 2.0 * 3.14 * x.radius;

   

    // calculate area

    x.area = 3.14 * x.radius * x.radius;

   

    // calculate volume

    x.volume = 4.0 * 3.14 * x.radius * x.radius * x.radius / 3.0;

   

    printf("Radius : %f\n", x.radius);

    printf("Perimeter : %f\n", x.perimeter);

    printf("Area : %f\n", x.area);

    printf("Volume : %f\n", x.volume);

   

    // open file in write mode

    FILE *ptr = fopen("circlePAV.txt", "w");

   

    fprintf(ptr, "Radius : %f\n", x.radius);

    fprintf(ptr, "Perimeter : %f\n", x.perimeter);

    fprintf(ptr, "Area : %f\n", x.area);

    fprintf(ptr, "Volume : %f\n", x.volume);

   

    return 0;

}

Sample Output

Enter radius 6.35 Radius6.350000 Perimeter:39.877998 Area: 126.612648 Volume 1071.987061

Add a comment
Know the answer?
Add Answer to:
write a c programming Write a program that will calculate the perimeter, area and volume of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In c programming . Part A: Writing into a Sequential File Write a C program called...

    In c programming . Part A: Writing into a Sequential File Write a C program called "Lab5A.c" to prompt the user and store 5 student records into a file called "stdInfo.txt". This "stdInfo.txt" file will also be used in the second part of this laboratory exercise The format of the file would look like this sample (excluding the first line) ID FIRSTNAME LASTNAME GPA YEAR 10 jack drell 64.5 2018 20 mina alam 92.3 2016 40 abed alie 54.0 2017...

  • 1. Write a program that determines the area and perimeter of a square. Your program should...

    1. Write a program that determines the area and perimeter of a square. Your program should accept the appropriate measurement of the square as input from the user and display the result to the screen. Area of Square = L (squared) Perimeter of Square = 4 * L 2.  Write a program that determines the area and circumference of a circle. Your program should accept the appropriate measurement of the circle as input from the user and display the result to...

  • Write a C++ program to compute the total volume of N cones, where N is a...

    Write a C++ program to compute the total volume of N cones, where N is a number entered by the user. Repeat the request for N until the user enters a positive number. For each cone, ask for the radius and height, compute the volume, and add that volume to the total. Each time you ask the user to enter either the height or the radius, if the user does not enter a positive number, display an error message and...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the...

    I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...

  • 2. Write a program with three functions that will be called from the main function The functions will calculate the...

    2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...

  • Use Python programming #3 on page 47 of your python programming book: Write a Tipper program...

    Use Python programming #3 on page 47 of your python programming book: Write a Tipper program where the user enters a restaurant bill total. The program should then display two amounts: a 15% tip and a 20% tip. Name your file tipper.py Previous Next.

  • Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the...

    Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the Area of a Circle 2.       Calculate the Area of a Triangle 3.     Calculate the Area of a Rectangle 4.       Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the formula:      area = ∏r2    Use 3.14159 for ∏. If the user enters 2 the program should ask for...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include...

    Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include <stdio.h> #define PI 3.14 typedef struct cylinder{    float r,h;    float areacircle=2*PI*r;    float areacylinder;    float volumecylinder;    areacylinder=2*PI*r*h+2*PI*r*r;    volumecylinder=PI*r*r*h; }; int main() {    float start,numcyls;    printf("How many cylinders do you want? Enter a positive integer.\n");    scanf("%f",&numcyls);    if(numcyls<1||ceilf(numcyls)!=numcyls)    while()    {printf("The number you have entered is not a positive integer. Please try again.\n");        printf("Remember,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT