90.pd file:///C:AUsers/ladmin/Downloads/hw3 7790 pdf colletworkturhen D Buckeye
ID: 642161 • Letter: 9
Question
90.pd file:///C:AUsers/ladmin/Downloads/hw3 7790 pdf colletworkturhen D Buckeye lnk ImlCarmen |lderttysnd Access M D osu writng Center No row is allowed to have less than two ""'s. You will write code to check for this. Write a program that prompts for an integer greater than one that represents the low end of a range and a second integer greater than or equal to the first integer that represents the high end of a range. The program will print the factors of integers in this range in descending order. For example, if the user enters 2 for the low end of the range and 6 for the high end of the range, then the program will output 2: 2, 1 3: 3, 1 4: 4, 2, 1 5: 5, 1 6: 6, 3, 2, 1 For both problems, write your code incrementally. This means write only enough code to solve a particular step in the algorithms provided below and then compile and test that portion thoroughly before writing your solution to the next algorithmic step. Test your code on small input values first and handle boundary and error cases early in coding your solution. 1. Program hourglass.cpp using the starter template provided: (a) Prompt and read in the number of 's in the top row; (b) If the number of 's is less than three, print the error message "Size of the top row must be at least three.", and prompt again for the number of's in the top row. Repeat until the user enters a valid number. (Use a while loop.) (c) Prompt and read in the number of rows from the top row to the middle row (d) If the number of rows is invalid then print Invalid number of rows." and prompt again for the number rows. An invalid number of rows would be a mumber less than 1 or a number that leads to a row in the hour glass with less than two Repeat until the user eaters a valid number of rows. (Use a while loop.) (e) Display an empty line (E) Use for loops to display the hour glass. Your outer for loop will iterate over the number of rows times. For each row use one nested for loop to display blanks (the top row contains no blanks) and another nested for loop to display the characters 7790.pdi-Go...Explanation / Answer
//Solution for first one
#include<iostream>
using namespace std;
int main()
{
int first,last;
int i,j;
do
{
cout<<"enter first number:";
cin>>first;
}
while(first<=0);
do
{
cout<<"enter second number:";
cin>>last;
}
while(last<first);
for(i=first;i<=last;i++)
{
cout<<first<<" :";
for(j=i;j>0;j--)
{
if(i%j==0)
cout<<j<<" ";
}
cout<<endl;
}
}//end of method main
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.