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
PROBLEM:Write a program that prompts the user to input first name, middle initial, and last name (in upper case) for an ID card. There is a 22-character limit that also includes spaces in between the names on the ID card. The following conditions/limitations are observed: A. If the first name, second name, middle initial, and last name exceed the character limit, use the first name initial and last name. B. If the last name’s character count is greater than or equal to the character limit, omit the second name and middle initial. Use the first name initial and truncate the last name to fit the character limit.  C. The spaces in between the first name, second name, middle initial, and last name should not be included in the input. D. If there is no second name or middle initial, input 0. E.  Omit any space in the last name, e.g., DE GUZMAN will be DEGUZMAN.
Program 2: Write a program that asks the user for a word or phrase. Check to see if it is a palindrome. A palindrome is a word that is spelled exactly the same forward and backwards such as radar or noon. Your program must also take case into account. If the user types Radar, it must still return that it is a palindrome. Do not worry about palindromes with spaces. You do not need to put any code in static methods, you do not need to worry about try/catch blocks, and you do not need to make the program run more than once. Test values that I will use in class:   Noon palindrome tacocat palindrome Hello not a palindrome   in java
C++ One way to create a pseudo-random three digit number (and we are including one- and two-digit numbers as well) is rand()%1000. That gives numbers from 000 to 999, which is just what we want. Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is too high then the program should display "Too high, try again." If the user's guess is lower than the random number the program should say "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number. The program should keep track of the number of guesses the user makes. When the user correctly guesses the random number, the program should display the number of guesses. As specified, have the program tell the player how many guesses were used. A good player should always be able to find a three-digit number in ten or fewer guesses. The programs needs to include a menu that allows the user to select easy (3 digit number),…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
This key word causes an object to be created in memory. a. create b. new c. object d. construct

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Refer to your answer to Checkpoint 14.35. In what package are the three classes?

Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)

The conditional operator takes this many operands. a. one b. two c. three d. four

Starting Out with Java: From Control Structures through Objects (6th Edition)

A(n) _______ eliminates the need to place a function definition before all calls to the function.

Starting Out with C++ from Control Structures to Objects (9th Edition)

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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
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