The program below is meant to print prime numbers between the given set of numbers. But when i run, it just prints out one number instead of other numbers in between.
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int z = 0;
cout << "Enter an integer: ";
cin >> a;
cout << "Enter another number: ";
cin >> b;
for (int i=a; i<=b; i++)
{
for (int j=2; j<i; j++)
{
if (i%j == 0)
{
z++ ;
break;
}
}
if (z == 0)
{
cout << i << endl;
}
}
}
Aucun commentaire:
Enregistrer un commentaire