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
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:-
Get Answers For Free
Most questions answered within 1 hours.