Convert this Java code to C++: public class Problem5 {     public static void main(String[] args) {       //loop variables        int i = 0;        int num = 0;        int num_count = 0;         //Empty String to store prime numbers        String primeNumbers = "";         //First for loop which runs from 1 to 10000        for (i = 1; i <= 10000; i++) {            int counter = 0;            //second for loop which runs from selected number to 1            for (num = i; num >= 1; num--) {                //using modulus operator to check if selected number is divisible by any number from num(i) to 1                if (i % num == 0) {                    counter = counter + 1;   //count the divisible                }            }            //if counter is 2 then it is prime number(divisible by themselves and one (1))            if (counter == 2) {                //Appended the Prime number to the String                primeNumbers = primeNumbers + i + " ";                num_count++;                //arrange numbers, 50 numbers per line                if (num_count == 30) {                    primeNumbers += "\n";                    num_count = 0;                }            }        }        //display prime numbers        System.out.println("Prime numbers from 1 to 10000: ");        System.out.println(primeNumbers);    }}

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Convert this Java code to C++:

public class Problem5 {

    public static void main(String[] args) {
       //loop variables
        int i = 0;
        int num = 0;
        int num_count = 0;

        //Empty String to store prime numbers
        String primeNumbers = "";

        //First for loop which runs from 1 to 10000
        for (i = 1; i <= 10000; i++) {
            int counter = 0;
            //second for loop which runs from selected number to 1
            for (num = i; num >= 1; num--) {
                //using modulus operator to check if selected number is divisible by any number from num(i) to 1
                if (i % num == 0) {
                    counter = counter + 1;   //count the divisible
                }
            }
            //if counter is 2 then it is prime number(divisible by themselves and one (1))
            if (counter == 2) {
                //Appended the Prime number to the String
                primeNumbers = primeNumbers + i + " ";
                num_count++;
                //arrange numbers, 50 numbers per line
                if (num_count == 30) {
                    primeNumbers += "\n";
                    num_count = 0;
                }
            }
        }
        //display prime numbers
        System.out.println("Prime numbers from 1 to 10000: ");
        System.out.println(primeNumbers);
    }
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education