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
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- What is the output of the following code segment?inta=3,b=4;if(ab)Write(Y);WriteLine(Z); Y Z YZ nothingarrow_forwardA. Write a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater than or equal to 3600, the program should display the number of hours in that many seconds.• There are 60 seconds in a minute. If the number of seconds entered by the user is less than 3600, but is greater than or equal to 60, the program should display the number of minutes in that many seconds.B. Write a function named biggest that receives three integer arguments and returns the largest of the three values.arrow_forwardCreate a different version of the program that: Takes a 3-digit number and generates a 6-digit number with the 3-digit number repeated, for example, 391 becomes 391391. The rule is to multiply the 3-digit number by 7*11*13. Takes a 5-digit number and generates a 10-digit number with the 5-digit number repeated, for example, 49522 becomes 4952249522. The rule is to multiply the 5-digit number by 11*9091. Times 11: A two-digit number can be easily multiplied by 11 in one's head simply by adding the digits and inserting that sum between the digits. For example, 43 * 11 has the resulting digits of 4, 4+3, and 3, yielding 473. If the sum between the digits is greater than 9, then the 1 is carried to the hundreds place. Complete the below program. Create a different version of the program that: Takes a 3-digit number and generates a 6-digit number with the 3-digit number repeated, for example, 391 becomes 391391. The rule is to multiply the 3-digit number by 7*11*13. Takes a 5-digit…arrow_forward
- Write the following function to draw a regular polygon:def drawPolygon(x = 0, y = 0, radius = 50, numberOfSides = 3):The polygon is centered at (x, y) with a specified radius for the bounding circle for the polygon and the number of sides. Write a test program that displays a triangle, square, pentagon, hexagon, heptagon, and octagon, as shown in Figure 6.12a.arrow_forward6. A palindrome is a number or text phrase that reads the same backwards or forwards. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a program that reads a 5 digit integer and determines whether it is a palindrome. Hint: One way to do this is to use division (/) and modulus (%) operators to separate the number into individual digits.arrow_forward1. Write a program that compares the values of y1 and y2 in the following expressions for values of n up to 100 in increments of 10. Does the result surprise you?arrow_forward
- 5. How Many Times? by Jemar Jude Maranga Jennie is an ice cream parlour owner. She only sells 9 different type of ice creams. The ice creams are labelled from number 1 to 9. In order to keep track of which ice cream type sells a lot, she hired her friend Lisa to make a program that will show the ice cream number(s) which were ordered more than once. Input A single line containing the ice cream numbers that were ordered. Treat as one number. 12116744 Output Shows the ice cream type that were ordered more than once. Prints "No repeated order", if all ice cream type wasn’t ordered more than once. Ice·cream·1·was·ordered·3·times Ice·cream·4·was·ordered·2·timesarrow_forwardQ1. Write a program that takes a range from the user and display all the even numbers between the range (a, b] which are divisible by 3 but not by 4. ‘(’ / ‘)’-means excluding the number and ‘[’ / ‘]’ – means including the number.arrow_forward3. Write a program that picks a random number between 1 and 100 inclusive. It then prompts the user to guess the number. If the user guesses the number, print out a congratulatory message and exit. Otherwise, indicate whether the guess was low or high and ask the user to try again. Hint: Use the rand() function.arrow_forward
- 1.Write program to iteratively compute Fibonacci numbers (named after an Italian mathematician).Some Fibonacci numbers are 1, 1, 2, 3, 5, 8, ... where the next number is found by summing the preceding two numbers. Your program will read in a number, like 7, report the first 7 numbers. in this case1,1,2,3,5,8,13. Your program is not assured of receiving good data, thus if -2 is received as the number of numbers, then an error should be reported.arrow_forwardNeed help with the code for this question: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example, it should output the individual digits of: 3456 as 3 4 5 6 8030 as 8 0 3 0 2345526 as 2 3 4 5 5 2 6 4000 as 4 0 0 0 -2345 as 2 3 4 5arrow_forwardExercise 4: Write a program that reads two pieces of information: the hourly wages and the number of hours worked by the employee. The program should then calculate the net salary of the employee and display the results as shown in Figure 4. Note that: the net salary of the employee is the sum of the basic wages (which is number of hours worked times the hourly wages) minus the Social Security fees; where the Social Security fees represent 10% of the Basic wages. Name your program Lab3_Id_ex4.py, where Id is your university Id. Include the design of your solution as comments at the beginning of your program. Test your solution with different input data. Please enter the employee hourly wages? 10 please enter the number of hours worked? 40 Basic Salary Hourly Wages Number of Social Net Salary Hours Security **** 10.000 40.00 400.000 40.000 360.000 **** Figure 4: Exercise 4 Sample Runarrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,