Question

In: Computer Science

Objectives To use selection statements To use repetition statement Problem Specification Skip by 7’s and 9’s...

Objectives

  • To use selection statements
  • To use repetition statement

Problem Specification

Skip by 7’s and 9’s

1. Generate n numbers between -100 and 100.

2. If the value is multiple of 7 or 9, replaced by *

3. Then change to new line after the multiple of 7 or 9 is appeared

Design Specification

  • Use if
  • Use if … else
  • Use while

Example:

Solutions

Expert Solution

A program to display the number between -100 and 100 by using while loop and if-else statement. If the value is multiple of 7 or 9 then print * otherwise print the number.

#include <iostream>
using namespace std;

int main()
{
//initialize the counter variable
int counter = -100;
cout<<"The list of the numbers between -100 and 100: "<<endl;
//display the list
//user of while loop
while(counter<=100)
{
//use of if and if else statement
if(counter % 7 == 0)
cout<<"*"<<endl;
else if(counter % 9 == 0)
cout<<"*"<<endl;
else
cout<<counter<<" ";
counter++;
}
return 0;
}

OUTPUT:

The list of the numbers between -100 and 100:

-100 *                                                                                                                          

*                                                                                                                               

-97 -96 -95 -94 -93 -92 *                                                                                                       

*                                                                                                                               

-89 -88 -87 -86 -85 *                                                                                                           

-83 -82 *                                                                                                                       

-80 -79 -78 *                                                                                                                   

-76 -75 -74 -73 *                                                                                                               

-71 *                                                                                                                           

-69 -68 -67 -66 -65 -64 *                                                                                                       

-62 -61 -60 -59 -58 -57 *                                                                                                       

-55 *                                                                                                                           

-53 -52 -51 -50 *                                                                                                               

-48 -47 -46 *                                                                                                                   

-44 -43 *                                                                                                                       

-41 -40 -39 -38 -37 *                                                                                                           

*                                                                                                                               

-34 -33 -32 -31 -30 -29 *                                                                                                       

*                                                                                                                               

-26 -25 -24 -23 -22 *                                                                                                           

-20 -19 *                                                                                                                       

-17 -16 -15 *                                                                                                                   

-13 -12 -11 -10 *                                                                                                               

-8 *                                                                                                                            

-6 -5 -4 -3 -2 -1 *                                                                                                             

1 2 3 4 5 6 *                                                                                                                   

8 *  

10 11 12 13 *                                                                                                                   

15 16 17 *                                                                                                                      

19 20 *                                                                                                                         

22 23 24 25 26 *                                                                                                                

*                                                                                                                               

29 30 31 32 33 34 *                                                                                                             

*                                                                                                                               

37 38 39 40 41 *                                                                                                                

43 44 *                                                                                                                         

46 47 48 *                                                                                                                      

50 51 52 53 *                                                                                                                   

55 *                                                                                                                            

57 58 59 60 61 62 *                                                                                                             

64 65 66 67 68 69 *                                                                                                             

71 *                                                                                                                            

73 74 75 76 *                                                                                                                   

78 79 80 *                                                                                                                      

82 83 *                                                                                                                         

85 86 87 88 89 *                                                                                                                

*                                                                                                                               

92 93 94 95 96 97 *                                                                                                             

*                                                                                                                               

100


Related Solutions

Longest ‘A’ Path Objectives Manipulating two-dimensional lists Using recursion to solve a problem Problem Specification Write...
Longest ‘A’ Path Objectives Manipulating two-dimensional lists Using recursion to solve a problem Problem Specification Write a Python application to find the longest ‘A’ path on a map of capital (uppercase) letters. The map is represented as a matrix (2-dimensional list) of capital letters. Starting from any point, you can go left, right, up and down (but not diagonally). A path is defined as the unbroken sequence of letters that only covers the spots with the letter A. The length...
MATLAB: Create your own problem in words that use loop and selection statements in the same...
MATLAB: Create your own problem in words that use loop and selection statements in the same problem. Create a problem that has a somewhat practical, real-life application like entering your PIN code at an ATM, and then after 4 incorrect tries, you are locked out of the ATM. Or create a problem based perhaps upon a physics or chemistry lab.   The problem should require the use of a WHILE loop, a FOR loop and a minimum of 3 selection statements...
Programming Project #1: Manage Simple Expenses Objectives: • Use basic C++ constructs: if, switch, repetition (looping)...
Programming Project #1: Manage Simple Expenses Objectives: • Use basic C++ constructs: if, switch, repetition (looping) and functions • Perform simple data type and string object manipulations • Solve problem, design solution and implement using C++ Description: Write a menu-driven program named “ManageSimpleExpenses” that provides the following options: 1. Earn 2. Spend 3. Show logs 4. Exit Basically, the program allows the user to enter earning or spending amounts and keep track of the current balance. It also print out...
E7-7 (Algo) Analyzing and Interpreting the Financial Statement Effects of LIFO and FIFO LO7-2, 7-3 Skip...
E7-7 (Algo) Analyzing and Interpreting the Financial Statement Effects of LIFO and FIFO LO7-2, 7-3 Skip to question [The following information applies to the questions displayed below.] Emily Company uses a periodic inventory system. At the end of the annual accounting period, December 31 of the current year, the accounting records provided the following information for product 2: Units Unit Cost Inventory, December 31, prior year 2,800 $ 13 For the current year: Purchase, April 11 8,960 14 Purchase, June...
E7-7 (Algo) Analyzing and Interpreting the Financial Statement Effects of LIFO and FIFO LO7-2, 7-3 Skip...
E7-7 (Algo) Analyzing and Interpreting the Financial Statement Effects of LIFO and FIFO LO7-2, 7-3 Skip to question [The following information applies to the questions displayed below.] Emily Company uses a periodic inventory system. At the end of the annual accounting period, December 31 of the current year, the accounting records provided the following information for product 2: Units Unit Cost Inventory, December 31, prior year 2,800 $ 13 For the current year: Purchase, April 11 8,960 14 Purchase, June...
Problem 9-9 Financing Deficit Garlington Technologies Inc.'s 2015 financial statements are shown below: Balance Sheet as...
Problem 9-9 Financing Deficit Garlington Technologies Inc.'s 2015 financial statements are shown below: Balance Sheet as of December 31, 2015 Cash $   180,000 Accounts payable $   360,000 Receivables 360,000 Notes payable 156,000 Inventories 720,000 Line of credit 0 Total current assets $1,260,000 Accruals 180,000 Fixed assets 1,440,000 Total current liabilities $   696,000 Common stock 1,800,000 Retained earnings 204,000 Total assets $2,700,000 Total liabilities and equity $2,700,000 Income Statement for December 31, 2015 Sales $3,600,000 Operating costs 3,279,720 EBIT $  320,280 Interest 18,280 Pre-tax earnings...
Problem 9-13 (Algo) Retail inventory method; various applications [LO9-3, 9-4, 9-5] Skip to question [The following...
Problem 9-13 (Algo) Retail inventory method; various applications [LO9-3, 9-4, 9-5] Skip to question [The following information applies to the questions displayed below.] On January 1, 2021, Pet Friendly Stores adopted the retail inventory method. Inventory transactions at both cost and retail, and cost indexes for 2021 and 2022 are as follows: 2021 2022 Cost Retail Cost Retail Beginning inventory $ 121,600 $ 190,000 Purchases 520,000 708,000 $ 630,000 $ 1,056,000 Purchase returns 2,500 5,000 3,000 3,600 Freight-in 4,200 6,000...
Objectives: Practice using selection structures within a complete C++ program to solve a problem. Be able...
Objectives: Practice using selection structures within a complete C++ program to solve a problem. Be able to understand and use linear interpolation in a program. Modify/Extend an existing program. Problem Description: Linear Interpolation There are two credit levels for this assignment. Completing the “B” level correctly is worth 16/20 points, completing the “A” level is worth 20/20. You are encouraged to get the code for the “B” level working first and then complete the “A” level if you have time/interest....
Objectives: use Scite Use recursion to solve a problem Create classes to model objects Problem :...
Objectives: use Scite Use recursion to solve a problem Create classes to model objects Problem : The Rectangle class (Filename: TestRectangle.java) Design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height....
Problem 9-7 Forecasted Statements and Ratios Upton Computers makes bulk purchases of small computers, stocks them...
Problem 9-7 Forecasted Statements and Ratios Upton Computers makes bulk purchases of small computers, stocks them in conveniently located warehouses, ships them to its chain of retail stores, and has a staff to advise customers and help them set up their new computers. Upton's balance sheet as of December 31, 2015, is shown here (millions of dollars): Cash $   3.5 Accounts payable $   9.0 Receivables 26.0 Notes payable 18.0 Inventories 58.0 Line of credit 0 Total current assets $ 87.5 Accruals 8.5...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT