Question

C++ language. please provide detailed comments (for beginners) and use easy to understand/trace code. Thank you...

C++ language. please provide detailed comments (for beginners) and use easy to understand/trace code.

Thank you

--------------------------------------------------

Given positive integers n, a, and b, print the first n positive integers that are a multiple of
a, b, or both.
For example: n = 6, a = 2 and b = 3, you should print: 2 3 4 6 8 9

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main()
{
    int n, a, b;
    
    // promting and reading value for n
    cout<<"Enter value for n: ";
    cin>>n;
    
    // promting and reading value for a
    cout<<"Enter value for a: ";
    cin>>a;
    
    // promting and reading value for b
    cout<<"Enter value for b: ";
    cin>>b;
    
    int i = 0, value = 1;
    while(i<n){
        // checking a is divisible by either of a or b
        if(value%a==0 || value%b==0){
            // printing value 
            printf("%d ",value);
            // incrementing value of i by 1
            i++;
        }
        // incrementing value by 1
        value++;
    }
    
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ language. please provide detailed comments (for beginners) and use easy to understand/trace code. Thank you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ language. please provide detailed comments (for beginners) and use easy to understand/trace code. Thank you...

    C++ language. please provide detailed comments (for beginners) and use easy to understand/trace code. Thank you --------------- A positive integer n is triangular if it can be obtained by the product of three consecutive positive integers. Given n > 0, determine whether n is triangular. For example, 120 is triangular, since 4 · 5 · 6 = 120.

  • *PYTHON EXPERTS ONLY PLEASE* Please provide the answer coded in Python using comments to explain code...

    *PYTHON EXPERTS ONLY PLEASE* Please provide the answer coded in Python using comments to explain code function. Good answers will be rated with thumbs up! Please answer both parts. Thank you for your time. Question 3 - Suppose you have a file named numbers.csv which contains a bunch of integers, five per line of text, separated by commas. Write code below that will open the _le, read the numbers from it, and print the sum of all the even numbers...

  • Please provide comments for each line, to make it easier to understand. Thank you! Write the...

    Please provide comments for each line, to make it easier to understand. Thank you! Write the following code in ARM 32 *AND* 64 bit assembly. Be sure to follow C calling conventions. char *strcpy(char *dst, char *src) { char *dst_copy = dst; while (*src) { (*dst) = (*src) ++dst; ++src; (*dst) = (*src) return dst_copy;

  • Please Use this as an example , no code is to be written Q8 Trace the...

    Please Use this as an example , no code is to be written Q8 Trace the execution of the following expressions using an evaluation tree. Use the values as follows: 1-5, j-7, k-4, m =-6, n-8, flag 1-0, flag2-1 (all integers), and a-: 3.5, b-8.0, c 0.0, d-40.0 (doubles) 3 (a -b) (2(cd))

  • C++ Programming help, please include comments to help me understand the code. Thank you for helping....

    C++ Programming help, please include comments to help me understand the code. Thank you for helping. Task C: Substitution and Hamming Distance For this task, we will explore mutations that occur by substitution. Your task is to write a program called hamming.cpp that calculates the Hamming distance between two strings. Given two strings of equal length, the Hamming distance is the number of positions at which the two strings differ. e. g.: Hamming("aactgc", "atcaga") would output 3. Notice that certain...

  • PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE...

    PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE 11. Initialize a integers in the two-dimensional array testArray to the values 1 through 9 using 1 or more while loops so that the array could be visualized as: 1 2 3 LA 5 6 7 8 9...

  • Make a Code in C++ language. The Code should not copy paste from internet. The code...

    Make a Code in C++ language. The Code should not copy paste from internet. The code should complete and should run. Also provide output. Make the code in easy way and also provide comments. The code should complete and Don't forget to provide output. 1. Make a cpp class TTT. 2. In that class, you will have two functions. one main function and one function named fib(). 3. Get the value of n from user in main function. n specifies...

  • Could you please provide a clear, detailed and easy to follow worked solution for the following...

    Could you please provide a clear, detailed and easy to follow worked solution for the following question. Please only answer if you are 100% sure you can solve it accurately. I will leave feedback that reflects the quality of your answer. Thank you.

  • C Programming: Functions Please answer 1 and 2 on paper in C code. Not C++ or...

    C Programming: Functions Please answer 1 and 2 on paper in C code. Not C++ or C# just C. If you could provide some comments with a brief explanation of why you did what you did, that would be very much appreciated. Thank you for your help!! :) 1. Write a function that takes a single float, and returns that number rounded as an integer (not truncated, rounded properly). Ex: round(4.5) -> 5, round (4.4) -> 4 2. Write a...

  • Please implement the following problem in basic C++ code and include detailed comments so that I...

    Please implement the following problem in basic C++ code and include detailed comments so that I am able to understand the processes for the solution. Thanks in advance. // personType.h #include <string> using namespace std; class personType { public: virtual void print() const; void setName(string first, string last); string getFirstName() const; string getLastName() const; personType(string first = "", string last = ""); protected: string firstName; string lastName; }; // personTypeImp.cpp #include <iostream> #include <string> #include "personType.h" using namespace std; void...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT