Santa Ana College/CMPR 120- Programming Concepts J. Hester Fall 2017 Homework #6
ID: 3600750 • Letter: S
Question
Santa Ana College/CMPR 120- Programming Concepts J. Hester Fall 2017 Homework #6 Due Thursday, October 26 A number is frabjous if (and only if) at least one of its digits is 7. Your non-negative integer values, representing a range of numbers to test, and u ranges as desired. Notes: If we wish to look at the individual digits of an integer named X many fabjous numbers are in that range. Your program should allow the user t coun The rightmost digit of X may be obtained with the expression X % 10. The rightmost digit of X may be removed from X using the statement X/ml * 0; By repeatedly looking at digits and then removing them, all digits of X may be processed exe demonstrates what your program should do. Notice that it gets is/are The program Gold06. correct as well as theon "number", depending on whether or not the count is 1. You should turn in (in a pocket folder): this assignment grading space below), your statement of completeness, a structure chart corresponding to outline comments in your code, and a full printout of your program. All documents should be appropriately labeled. You should also place a folder named "Homework 06" containing Vour Main.cpp file into the private folder of your FTP site. sheet (write your name in the Grading Sheet, Homework #6 Name: Possible Achieved Criteria Statement of Completeness Structure Chart Clear Indentation and Spacing Internal Code Comments Appropriate Use of Variables Appropriate Use of Statements& Expressions Complete/No Errors Output Format and Correctness Presentation Total Notes: 5 43Explanation / Answer
This program first input two numbers n1 and n2. There is a for loop executing from n1 to n2 to fins out frabjous numbers between these two. Inside for loop there is while loop which iterates over digits of a number till either all the digits have been processed or a 7 is found. In every iteration it divides number by 10 to remove its rightmost digit. If a 7 is found, count is incremented by one and flag is set to 1 indicating 7 is found. In the print the value of count indicating number of frabjous numbers between n1 & n2.
#include<iostream.h>
void main(){
int n1,n2,i,count=0,num,flag=0;
cout<<”Enter two non-negative integers”<<endl;
cin>>n1>>n2;
for(i=n1; i<=n2; i++){
flag =0;
num = i;
while(num > 0 && flag == 0){
if(num%10 == 7)
{
count++;
flag =1;
/* continue to next iteration of the loop so that even if num contains more than one 7 count should be incremented only once for a number */
}
else{
num = num/ 10;
}
}
}
cout<<”Total number of frabjous: ”<<count<<endl;
}
If this helps please give a thumbs up. Good Luck!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.