Concept explainers
Type in and run the nine programs presented in this chapter. Compare the output produced by each
“for” condition:
The “for” condition is used to repeat the particular block until some end condition is met.
Syntax:
for (init; condition; increment)
{
//statement
}
Here, “init” is allow the user to declare and initialize any loop control variables. The “condition” is evaluated and “increment” is used to increment the values of the variable.
Explanation of Solution
Program:
Consider the five programs presented in the given chapter.
Program 4.1:
The following program will calculate the eighth triangular number:
//include the header file
#include <stdio.h>
//definition of main method
int main (void)
{
/*declare a variable*/
int triangularNumber;
//calculate the "triangularNumber"
triangularNumber = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8;
//display the result
printf ("The eighth triangular number is %i\n", triangularNumber);
//return statement
return 0;
}
Explanation:
In the above program, declare the variable and calculate the eighth triangular number. Then display the values using “printf” function on the output screen.
Sample Output for program 4.1:
The eighth triangular number is 36
Want to see more full solutions like this?
Chapter 4 Solutions
Programming in C
Additional Engineering Textbook Solutions
Experiencing MIS
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Digital Fundamentals (11th Edition)
Starting Out With Visual Basic (7th Edition)
- (Heat transfer) The formula developed in Exercise 5 can be used to determine the cooling time, t, caused only by radiation, of each planet in the solar system. For convenience, this formula is repeated here (see Exercise 5 for a definition of each symbol): t=Nk2eAT3fin A=surfaceareaofasphere=4r2 N=numberofatoms=volumeofthespherevolumeofanatom Volume of a sphere sphere=43radius3 The volume of a single atom is approximately 11029m3 . Using this information and the current temperatures and radii listed in the following chart, determine the time it took each planet to cool to its current temperature, caused only by radiation.arrow_forwardProblem B Musical Key ConversionThe chromatic scale is a 12-note scale in music in which all notes are evenly spaced: that is, the ratio of the frequency between any two consecutive notes is constant. The notes are typically labeled in the following sequence: A, A#, B, C, C#, D, D#, E, F, F#, G, G# After G#, the labels loop back and start over with A (one octave higher). To convert between musical keys, you can shift all notes in a piece of music a constant number of steps along the scale above. For example, the sequence of notes E, E, F, G, G, F, E, D, C, C, D, E, E, D, D can be converted to another musical key by shifting everything up three steps: E, E, F, G, G, F, E, D, C, C, D, E, E, D, D G, G, G#, A#, A#, G#, G, F, D#, D#, F, G, G, F, F Notice that G was converted to A#, since going three steps up required us to loop off of the top of the scale back to the bottom: G -> G# -> A -> A#. Technically we should note that this would be A# of the next octave up, but we’ll…arrow_forwardWhat do parentheses do in mathematical equations? a. Ensure addition functions are performed before subtraction functions b. Ensure multiplication functions are performed before division functions c. Ensure multiplication functions are performed before addition functions d. Ensure that whatever operation is inside the parentheses is performed firstarrow_forward
- Create a truth table that corresponds to the combinational function listed below. 1) F(X, Y, Z) is true when exactly one of the following is true: a) X is true b) Y is false and Z is truearrow_forwardPYTHONarrow_forward1)Create a function that takes Celsius temperature and returns a Fahrenheit. Study CURSOR with parameters chapter, and Cursor For Loop. Use a cursor FOR loop inside your procedure.arrow_forward
- Which sentence is correct about the local variables? A) Each local variable only can be accessed inside its function. B Each local variable only can be accessed inside its loop. (C) all of these choices (D Each local variable only can be accessed inside all functions.arrow_forwardDigital lab & design The circuits don’t have to be created in proteus project just a normal drawing on paper will do, thanks. 1)arrow_forwardMovies(mid,mname,releasedate,rating) Stars(sid,sname,gender,birthday) Casting(sid,mid) TCR and DCR Find the casting of “isle of dogs” (i.e. find all stars’ names who cast in “isle of dogs”)arrow_forward
- by using lists Please Write Python program design at the beginning of program:define the purpose, Input /output data and Algorithm and please write the program testing ( for cases that could happen) and write comments in each stepsarrow_forwardProblem B. Musical Key ConversionThe chromatic scale is a 12-note scale in music in which all notes are evenly spaced: that is, the ratio of the frequency between any two consecutive notes is constant. The notes are typically labeled in the following sequence: A, A#, B, C, C#, D, D#, E, F, F#, G, G# After G#, the labels loop back and start over with A (one octave higher). To convert between musical keys, you can shift all notes in a piece of music a constant number of steps along the scale above. For example, the sequence of notes E, E, F, G, G, F, E, D, C, C, D, E, E, D, D can be converted to another musical key by shifting everything up three steps: E, E, F, G, G, F, E, D, C, C, D, E, E, D, D G, G, G#, A#, A#, G#, G, F, D#, D#, F, G, G, F, F Notice that G was converted to A#, since going three steps up required us to loop off of the top of the scale back to the bottom: G -> G# -> A -> A#. Technically we should note that this would be A# of the next octave up, but we’ll…arrow_forwardxii) In MATLAB, write a program to find the sum of natural numbers from 100 to 200(both inclusive). Display the sum in the output.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning