Question #60577

Write a program in c++ to print the prime numbers between 100-200

Expert's answer

Answer on Question #60577 - Programming & Computer Science - C++

Question:

Write a program in c++ to print the prime numbers between 100-200.

Solution:

#include <iostream>
#include <math.h>
int main()
{
    for (int i=100; i<200; i++)
    {
        for (int j=2; j*j<=i; j++)
        {
            if (i % j == 0)
            {
                break;
            }
            else if (j+1 > sqrt(i))
            {
                std::cout << i << " ";
            }
        }
    }
    return 0;
}

Answer:

101 103 107 109 113 127 131 137 139 149 151 157 163 167 173

179 181 191 193 197 199</math.h></iostream>

LATEST TUTORIALS
APPROVED BY CLIENTS