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
USE C++ (Display matrix of 0s and 1s) Write a function that displays an n-by-n matrix using the following header: void printMatrix(int n) Each element is 0 or 1, which is generated randomly. Write a test program that prompts the user to enter n and displays an n-by-n matrix. Here is a sample run:
(Written in C)   Create a payroll program to store and calculate the payroll for a small company as follows:Create an array of floats that is 4 rows and 50 columns, with the columns being the number of employeerecords stored in the array.Program parameters are as follows:Create a menu in a function menu and call it with the following options (use a do-while loop):A or a to add employee infoD or d to display employee infoT or t to display total payrollS or s to display the info of all employeesC or c to display the count of employees present in the arrayF or F to delete a recordZ or z to exit programThe information for each employee is: employee number, hours worked, pay rate per hour, taxdeduction.Option A or a:Call the function possible to check and if the index returned is 50 then output a msg saying that thearray is full. If the index returned is less than 50 the call the function add, pass to it the available index asthe third argument and the function will ask the user for one…
[Python (py3)] Please create a code that solves for matrix addition and matrix scalar multiplication. The code for scalar multiplication is already written below, just incorporate the code for matrix addition. The input will come from file1.txt, and the output should be printed to output.txt Note for matrix addition: When the dimension of Matrix A is not equal to the dimension of Matrix B, print "Matrix addition cannot be performed; dimensions are unequal." Format of the input from file1.txt:First Line: type of operation (add or scalmultiply)Second Line: matrix A dimension (example: if 3 rows and 2 columns, type 3 2)Third Line: matrix A elementsFourth Line: matrix B dimension (or the scalar number for the operation of scalar multiplication)Fifth Line: matrix B elements (not needed for scalar multiplication) Sample input 1:add2 2 53 -47 312 267 2-34 6 Sample output 1:120 -2-27 37 Sample input 2:scalMultiply2 253 -47 312Sample output 2:106 -814 62…
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