Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1 (Language C++ / Try to run it in CodeRunner first) A) B) Write a program that asks for the end value (positive integer), and

Q1 (Language C++ / Try to run it in CodeRunner first)

A)image text in transcribed

B) image text in transcribed

Write a program that asks for the end value (positive integer), and computes the sum of the odd numbers from 0 to the value entered, inclusive. If the user enters a negative value as input then print Invalid input. For example: Test Input Result // test case example 1 20 Enter a positive number: Sum: 100 // test case - example 2 -1 Enter a positive number: Invalid input. Write a program that takes a positive integer n, and prints the sequence as explained below, If n is a multiple of 3, then the next value in the sequence is n-1. Otherwise, the next value in the sequence is n/2 (integer division). The sequence continues until n is positive. Please note that the sequence should not contain any negative values or 0. Make sure your program validates the user input. For invalid inputs, print "Invalid input." For example: Test Input Result // test case example 1 13 Enter a positive number: 13 6 5 2 1 // test case - example 2 -10 Enter a positive number: Invalid input

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

2 What are the implications for logistics strategy?

Answered: 1 week ago