Question

In: Computer Science

1. Write a for loop that will display all of the multiples of 3, one per...

1. Write a for loop that will display all of the multiples of 3, one per line.

The starting point is a variable called lower, and the ending point is an integer called upper, inclusive.

The "lower" and "upper" variables have been properly declared and assigned values where the value of lower is less than or equal to the value of upper. Declare any other variables that are needed.

2. Write a "while" loop that does the same thing as the following "for" loop.

for (i=6;i<1000;i+=5)

   cout<<i<<endl;

3. Write an if statement to print the message "The size is valid" if the variable named size is in the range 5 to 18, including 5 and 18. Otherwise print "The size is not valid".

Solutions

Expert Solution

ANSWERS;

1.)

CODE:

#include<iostream>
using namespace std;
int main()
{
int lower = 3;//declaring lower variable
int upper = 20;//declaring upper varaiable
int i;//loop variable
cout<<"Multiples of 3 : "<<endl;
//for loop to print Multiples of 3.
for(i=lower;i<=upper;i++)
{
//codition to check whether given number is divisible by 3.
if(i%3==0)
{
cout<<i<<endl;//printing number line by line.
}
}
}
CODE ATTACHMENTS:

2.)

CODE:

#include<iostream>
using namespace std;
int main()
{
int i;//loop variable
i=6;//initialising value
//while loop that resembles for loop given.
while(i<1000)
{
cout<<i<<endl;//printing as needed.
i+=5;//incrementing variable.
}
}

CODE ATTACHMENTS:

3.)

CODE:

#include<iostream>
using namespace std;
int main()
{
int size;//declaring size variable
cout<<"Enter size : ";
cin>>size;//taking size from user
//if condition to check the size in range or not.
if(size>=5 && size<=18)
{
cout<<"The size is valid";
}
else
{
cout<<"The size is not valid";
}
}

CODE ATTACHMENTS;

Thank You.

Please comment for any queries.

Please rate it.


Related Solutions

Write a Java loop statement that prints count. Count begins with 1. It increments as multiples...
Write a Java loop statement that prints count. Count begins with 1. It increments as multiples of 2 and does the loop until count is less than 50.
Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending...
Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending in 3. • Write a for loop to display a string entered by the user backwards.
Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
JAVA Write a for loop which will display this set of values 1,3,5,7,9.
JAVA Write a for loop which will display this set of values 1,3,5,7,9.
Write a C program that meets the following requirements. Uses a while loop to display the...
Write a C program that meets the following requirements. Uses a while loop to display the first 10 natural numbers (on one row, with a tab separating each number) Uses a while loop to find the sum of the second set of 10 natural numbers. Reads a user entry and displays all the natural numbers up to the user entry (on a column list with a new line separating each number). Finds and displays the sum of all natural numbers...
1. Write the statement that will display all of the information in the PetOwner table using...
1. Write the statement that will display all of the information in the PetOwner table using the asterisk (*) notation. 2. Write the statement that will display all of the information in the PetOwner table without using the asterisk (*) notation. 3. Write the statement that will display the first and last names of the owners in that order. 4. Write the statement to display the breed, type and DOB of all pets having a type of Cat. 5. Write...
IN C++: Write a program to display the following table. MUST use for-loop Enter the table...
IN C++: Write a program to display the following table. MUST use for-loop Enter the table size: 10 N N^2 Square root of N --------------------------------------------- 1 1 1.00 2 4 1.41 3 9 1.73 ….. 10 100 3.16
1. Write a bash command that will display the value of all environment variables defined in...
1. Write a bash command that will display the value of all environment variables defined in your shell process, sorted in alphabetical order, and numbered. Here is a sample of the type of output your command should produce: 1 } 2 ALSA_CONFIG_PATH=/etc/alsa-pulse.conf 3 AUDIODRIVER=pulseaudio 4 BASH_FUNC_mc%%=() { . /usr/share/mc/mc-wrapper.sh 5 COLORTERM=1 2. Write a bash command that will display the value (and only the value) of the JAVA_ROOT environment variable. Here is a sample of the type of output your...
Write a PHP Program to display all the $_SERVER elements
Write a PHP Program to display all the $_SERVER elements
Write a for loop from 1 to 3 using i as the variable. For each value...
Write a for loop from 1 to 3 using i as the variable. For each value of i: Create a vector x of 10 random numbers between 0 and 1. Create a second vector t which is equal to ten integers from 1 to 10. Plot x versus t in figure 1. Use hold on to keep each plot. Use a different color for the line for each value of i. At the very end, add the text 'time' using...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT