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)
- (Desk check) Determine the output produced by the following program: includeiostreamusingnamespacestd;intmain()inti,j,val[3][4]={8,16,9,52,3,15,27,6,14,25,2,10};for( i=0;i3;++i)for( j=0;j4;++j)coutval[i][j];return0;arrow_forwardBased on the given program and the sample output, please provide the missing code.arrow_forwardFor each of the programs below, in the blank in the code below so that it prints out "decode". If this is not possible instead write "Not Possiblearrow_forward
- Solve the part d in accordance with the program given make whatever changes or omissions are required paste the screenshot of program and outputarrow_forwardPLZ help with the following: Show the output of following programarrow_forwardPlease follow all the steps in detail. Follow the desired output of the program as shown below.arrow_forward
- 3. Locate the error in each of the following program segments and explain how to correct it.arrow_forwardQ(2): Given a quadratic equation, 2 x^2-3 x+1=0, the roots of this equation are given by, x= (-b±√(b^2-4ac))/2a. find the roots x1 and x2 using command windows or script file of matlab program. Upload the program as pdf file with the results.arrow_forwardCreate 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_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