In: Computer Science
Objectives
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
Example:
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