C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 13, Problem 13.4E
Program Plan Intro

Program Plan:

define keyword is used to define macros

An object-like macros is defined i.e.

#define pi 3.14

A function-like macros is defined i.e.

#define VOL( x ) ( 4.0 / 3 ) * pi * ( x * x * x )

Variable r is declared to store the value of radius.

printf (): used to print the data onto output screen.

Program Description: Purpose of the program is to define macros tofind the volume of sphere for radius values ranging from 1 to 10 in tabular form.

Expert Solution & Answer
Check Mark

Explanation of Solution

Program: Following is C++ program that defines macros to find the volume of sphere for radius values ranging from 1 to 10.

#include<stdio.h>//header file for input output
//defining macros 
#define pi 3.14 
#define VOL( x ) ( 4.0 / 3 ) * pi * ( x * x * x ) 
//start of main
intmain() 
{
//defining variable for storing value of radius 
int radius; 
//tabular reprsentation of data 
printf( "Radius\tVolume of sphere\n" ); 
printf( "\n" ); 
//for loop to iterate over the value of radius ranging from 1 to 10
for (radius = 1; radius < 11; radius++ ) 
    {
printf( "%d\t%f\n", radius, VOL( radius ) ); 

    } 
}//end of main 

Explanation:

The given C++ program calculates the volume of sphere.

For declaring the macros statements the define keyword is used for VOL(x) and pi.

Then using the for loop to iterate over the radius variable from 1 to 10 and to print one by one via “\n”. The “\t” is used to print six spaces between the radius and their volume.

Sample Output:

  C How to Program (8th Edition), Chapter 13, Problem 13.4E

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Which tool takes the 2 provided input datasets and produces the following output dataset? Input 1: Record First Last Output: 1 Enzo Cordova Record 2 Maggie Freelund Input 2: Record Frist Last MI ? First 1 Enzo Last MI Cordova [Null] 2 Maggie Freelund [Null] 3 Jason Wayans T. 4 Ruby Landry [Null] 1 Jason Wayans T. 5 Devonn Unger [Null] 2 Ruby Landry [Null] 6 Bradley Freelund [Null] 3 Devonn Unger [Null] 4 Bradley Freelund [Null] OA. Append Fields O B. Union OC. Join OD. Find Replace Clear selection
What are the similarities and differences between massively parallel processing systems and grid computing. with references
Modular Program Structure. Analysis of Structured Programming Examples. Ways to Reduce Coupling. Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,