Programming in C
Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 4, Problem 8E

Program 4.5 allows the user to type in only five different numbers. Modify that program so that the user can type in the number of triangular numbers to be calculated.

Expert Solution & Answer
Check Mark

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.

Sample Output

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?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Considering the TM example of binary sum ( see attached)do the step-by-step of execution for the binary numbers 1101 and 11. Feel free to use the Formal Language Editor Tool to execute it; Write it down the current state of the tape (including the head position) and indicate the current state of the TM at each step.
I need help on inculding additonal code where I can can do the opposite code of MatLab, where the function of t that I enter becomes the result of F(t), in other words, turning the time-domain f(t) into the frequency-domain function F(s):
I need help with the TM computation step-by-step execution for the binary numbers 1101 and 11.  Formal Language Editor Tool can be used to execute it; Write it down the current state of the tape (including the head position) and indicate the current state of the TM at each step;

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Control Structure in Data Structure - Data Structures - Computer Science Class 12; Author: Ekeeda;https://www.youtube.com/watch?v=9FTw2pXLhv4;License: Standard YouTube License, CC-BY