vendredi 4 novembre 2022

Why 2 is not showing prime?

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int i = 2;
    while(i<n){
        if(n%i==0){
            cout<<"not Prime";
            break;
        }else{
            cout<<"Prime";
            break;
        }
        i++;
    }
    return 0;
}

This code is written for showing prime or composite/notPrime numbers but 2 is prime & why it is not showing in output?

I write this code for getting for identifying that given number is prime or not. It can work on any number/digit but it can't show about "2" . So why is it?

Aucun commentaire:

Enregistrer un commentaire