Tech Me All

Tips ,Tricks notes and Quizes

Program to find the number is prime or not

Program to find the number is prime or not

#include<iostream.h>

#include<conio.h>

class student

{

int p,i,flag;

public:

void prime();

};

void student::prime()

{

cout<<“Enter the no : “;

cin>>p;

flag=0;

for(i=2;i<=p/2;i++)

{

if(p%i==0)

{

flag=1;

break;

}

}

if(flag==0)

{

cout<<“Nunber is prime”;

}

else

{

cout<<“Number is not prime”;

}

}

void main()

{

student s;

clrscr();

s.prime();

getch();

}

 

Output-

output2

1 Comment

Add a Comment
  1. Hurrah, that’s what I was searching for, what a information! present here at this
    blog, thanks admin of this site.

Leave a Reply

Your email address will not be published. Required fields are marked *

three × 1 =

Tech Me All © 2016 Frontier Theme