Question

b. wg. Prompt the user to input the value of a double variabler, which stores the radius of a sphere. The program then output

No. 7

7th question

i want this code to be done on c++ visual studio without using bool operation.
and please try to make as simple as possible.
Also i need flowchart for the code
thanks.

Write a program to test the functions described in Exercises 23 and 26 of this chapter Write a program that prompts the user

Q7

I need a code programmed on c++ visual studios.
Also flowchart of the code.
Try to make it simple college level understandable code.
thanks.



0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

bool isPrime(int number)
{
   if (number == 1) {
       return false;
   }
   for (int i = 2; i*i <= number; i++) {
       if (number % i == 0) {
           return false;
       }
   }
   return true;
}


int primeSum(int left, int right)
{
   int sum = 0;
   for (int i = left; i <= right; i++) {
       if (isPrime(i)) {
           sum += i;
       }
   }
   return sum;
}

void printTwinPrimes(int left, int right)
{
   int count = 0;
   for (int i = left; i + 2 <= right; i++)
   {
       if (isPrime(i) & isPrime(i + 2))
       {
           cout << "(" << i << ", " << (i + 2) << ")" << endl;
           count++;
       }
   }
   cout << "twin primes total count :: " << count;
}

int main()
{
   int left, right;
   cout << "enter left range value";
   cin >> left;
   cout << "enter right range value";
   cin >> right;
   cout << primeSum(left, right) << endl;
   cout << "twin primes :-" << endl;
   printTwinPrimes(left, right);

}enter left range value5 enter right range value100 1055 twin primes :- (5, 7) (11, 13) (17, 19) (29, 31) (41, 43) (59, 61) (7

Start get input range OL icright i is prime sumum ti i right i and i+2 are puti and i+1 print count end

Add a comment
Know the answer?
Add Answer to:
No. 7 7th question i want this code to be done on c++ visual studio without...
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
  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Program 4:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Program 4: A palindromic prime number is a number that is both prime number and a palindrome number. For example, 131, 313, and 757 are palindromic prime numbers. Design (pseudocode) and implement (source code) a program (name it PalindromicPrime) to display the first 50 palindromic prime numbers, 10 per line separated by one space. The program defines the following methods: Method isPalindome() to check if a...

  • please solve this question easiest way I saw the other answers but those are not solve...

    please solve this question easiest way I saw the other answers but those are not solve my program Twin primes are two consequetive odd numbers that are prime. Write a function that returns 1 if the input is a prime and O otherwise. int is_prime(int number) { Write a C Program to generate all twin primes in a given range of numbers using the is_prime function. Your program will input following from the command line: min : start of range,...

  • Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4...

    Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4 x 5 two-dimensional array. The program should use loops to populate the array using the rand, srand and time functions with random numbers between 10 and 60. After the values have populated the array, output the values of the array to the screen in something that looks like a 4 x 5 table.

  • Can someone help me with this coding question. I cannot get this to run properly. Write...

    Can someone help me with this coding question. I cannot get this to run properly. Write a program that defines the named constant PI, const double PI = 3.14159;, which stores the value of π. The program should use PI and the functions listed in Table 6-1 to accomplish the following: Output the value of √π . Prompt the user to input the value of a double variable r, which stores the radius of a sphere. The program then outputs...

  • In C program #include<stdio.h> The first 11 prime integers are 2, 3, 5, 7, 11, 13,...

    In C program #include<stdio.h> The first 11 prime integers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31. A positive integer between 1 and 1000 (inclusive), other than the first 11 prime integers, is prime if it is not divisible by 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31. Write a program that prompts the user to enter a positive integer between 1 and 1000 (inclusive) and that outputs whether the number...

  • Program must be in C language and MUST be able to run on visual studio 2....

    Program must be in C language and MUST be able to run on visual studio 2. Using Pointers and Arrays 2.1 Write a function bubblesort which will accept an array of double precision floating point numbers of length N and sort the array. Ref: https://en.wikipedia.org/wiki/Bubble_sort (I can verify this is accurate) 2.2 Write a program which exercises the bubblesort. For a good test, the program should have more than 20 values.

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns...

  • Hello, Is anyone able to do the C++ programming for the below in visual studio. The...

    Hello, Is anyone able to do the C++ programming for the below in visual studio. The code online is giving me errors. It just needs to be very very simple as I am a beginner. I have not learned functions yet but can include the math library. I have only 1 hour. thanks Write a program that reads from the user a positive integer (in a decimal representation), and prints its binary (base 2) representation. Your program should interact with...

  • Visual Studio Code C# Well Document everyline saying what the code does. Include designer code and...

    Visual Studio Code C# Well Document everyline saying what the code does. Include designer code and .cscode Extra 6-1 Create a simple calculator In this exercise, you'l1 create a form that accepts two operands and an operator from the user and then performs the requested operation. Simple Calculator Operand 1: 86 Operator Operand 2 11.11 Resut 7.7408 1. Start a new project named SimpleCalculator in the Extra Exercises Chapter 06SimpleCalculator directory 2. Add labels, text boxes, and buttons to the...

  • Please answer this question in C++. Also, please write it with 'using namespace std' because the other ways some of you do it is confusing. Class Exercise Write a program that does the follow...

    Please answer this question in C++. Also, please write it with 'using namespace std' because the other ways some of you do it is confusing. Class Exercise Write a program that does the following: 1. Defines a class named Data that has the following members a. A vector of integers entitled numbers (Private) b. Methods (Functions) (Public): i. Display_Menu Prompts the user to choose one of the following 0. Quit 1. Input Numbers 2. Display Numbers 3. Search Numbers 4....

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
ADVERTISEMENT