Question

Write a program to calculate the sum of all prime numbers between 100 and 200, including....

Write a program to calculate the sum of all prime numbers between 100 and 200, including. A prime number is a natural number greater than 1 and can only be divided by 1 and itself. For example, 5 is a prime number because 5 can only be divided by 1 and 5. we are currently using cin/cout, for /while loops

Homework Answers

Answer #1

Code:-

#include <iostream>
using namespace std;
int main()
{
int i,k=0,flag=0;
for(int x=100;x<=200;x++)
{
   k=x/2;
   for(i=2;i<=k;i++)
   {
if(x%i==0)
{
flag=1;
break;
}
   }
   if (flag==0)
   {
       cout <<x <<" is a prime number.\n";  
   }
   flag=0;
}
return 0;
}

Indentation:-

Output:-

Know the answer?
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
Similar Questions
1) Write a C program to print the prime numbers from 1 to 100. (A prime...
1) Write a C program to print the prime numbers from 1 to 100. (A prime integer is any integer that can be divided evenly only by itself and 1) Requirement: Use an array to take the number from 1 to 100 and another array to take the prime number.
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
PYTHON 3 Write a program that prints the count of all prime numbers between A and...
PYTHON 3 Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 21212 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules: You should first...
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers...
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 55000 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules:...
Prime Numbers) Write a program to calculate and print a list of all prime numbers from...
Prime Numbers) Write a program to calculate and print a list of all prime numbers from 1 to 100. C programming
use python Write a program that uses a for loop to display all prime numbers within...
use python Write a program that uses a for loop to display all prime numbers within the range [500, 800] (hint: prime numbers are numbers that have only 2 factors: 1 and themselves. You can use a loop function to check if a number has a factor other than 1 or itself using % operation)
write a C++ program that display a prime numbers between 1 and 100 number. Plase print...
write a C++ program that display a prime numbers between 1 and 100 number. Plase print the remaining primes by “dots” For gexample The output should appear like The prime numbers between 1 and 100 are: 1, 2, 3, 5, 7, .........
Please code C# 7. Write a program that can calculate the sum of all numbers between...
Please code C# 7. Write a program that can calculate the sum of all numbers between 1 and 1000 inclusive (including 1 and 1000)
1- Write a program to print only the even numbers from 100 to 200 2- Write...
1- Write a program to print only the even numbers from 100 to 200 2- Write a program to print the odd numbers from 22 – 99 3- Write a program to calculate howe many even number from 10 to 120 1- Write a program to find only the even numbers for 12 different numbers 2- Write a program to find the odd numbers for 10 different numbers 3- Write a program to calculate howe many even number and how...
Using for loops: - write a Java program that adds numbers between 1 to 100 and...
Using for loops: - write a Java program that adds numbers between 1 to 100 and prints the result. - write a Java program that adds odd numbers between 1 to 100 and prints the result - write a Java program that averages even numbers between 5 to 30 and prints the result