
Concept explainers

Explanation of Solution
Modified Program:
The following program will ask the user to enter the total number of triangular they want and calculate the triangular number using nested “for” condition:
//include the header file
#include <stdio.h>
//definition of main method
int main (void)
{
//declare the variables
int n, number, triangularNumber, counter, count;
//get the input from the user
printf("How many triangular would user want?");
scanf("%i", &count);
//check the condition
for (counter = 1; counter <=count; ++counter)
{
//get the input from the user
printf("What triangular number do you want? ");
scanf("%i", &number);
//set the value
triangularNumber = 0;
//check the condition
for (n = 1; n <=number; ++n)
//calculate the "triangularNumber" value
triangularNumber = triangularNumber + n;
//display the result
printf("Triangular number %i is %i\n", number, triangularNumber);
}
//return statement
return 0;
}
Explanation:
In the above program, declare the required header file. Inside the main method, declare the necessary variables and ask the user to enter the total number of triangular they want. The “for” condition is used to get the input from the user then nested “for” condition is used to iterate the “n” value up to the user entered input and inside the loop calculate the triangular of “n” value and display the result on the output screen.
How many triangular would user want? 2
What triangular number do you want? 12
Triangular number 12 is 78
What triangular number do you want? 25
Triangular number 25 is 325
Want to see more full solutions like this?
Chapter 4 Solutions
Programming in C
Additional Engineering Textbook Solutions
Electric Circuits. (11th Edition)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Mechanics of Materials (10th Edition)
SURVEY OF OPERATING SYSTEMS
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- Ensure you answer the question asked at the end of the document. Do not just paste things without the GNS3 console outputsarrow_forward"Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward"Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward
- "Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward"Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forwardSolve this "Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward
- "Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward"Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forwardSpecifications: Part-1Part-1: DescriptionIn this part of the lab you will build a single operation ALU. This ALU will implement a bitwise left rotation. Forthis lab assignment you are not allowed to use Digital's Arithmetic components.IF YOU ARE FOUND USING THEM, YOU WILL RECEIVE A ZERO FOR LAB2!The ALU you will be implementing consists of two 4-bit inputs (named inA and inB) and one 4-bit output (named out). Your ALU must rotate the bits in inA by the amount given by inB (i.e. 0-15).Part-1: User InterfaceYou are provided an interface file lab2_part1.dig; start Part-1 from this file.NOTE: You are not permitted to edit the content inside the dotted lines rectangle. Part-1: ExampleIn the figure above, the input values that we have selected to test are inA = {inA_3, inA_2, inA_1, inA_0} = {0, 1, 0,0} and inB = {inB_3, inB_2, inB_1, inB_0} = {0, 0, 1, 0}. Therefore, we must rotate the bus 0100 bitwise left by00102, or 2 in base 10, to get {0, 0, 0, 1}. Please note that a rotation left is…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,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
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT



