Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


write the prime no program in c++?

Answers were Sorted based on User's Feedback



write the prime no program in c++?..

Answer / virendra kumar

series of prime no

Is This Answer Correct ?    0 Yes 0 No

write the prime no program in c++?..

Answer / tuhin pal chowdhury

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
int flag = 0;
cout<<"Enter a number"<<endl;
cin>>num;
for(int i=2;i<num;i++)
{
if((num%i) == 0)
{
flag = 1;
break;
}
}
if (flag == 1)
cout<<"Not Prime"<<endl;
else
cout<<"Prime"<<endl;
getch();
}

Is This Answer Correct ?    1 Yes 2 No

write the prime no program in c++?..

Answer / ashwin kanjariya

I accept the last function since it has less time complexity than all other functions........

Is This Answer Correct ?    4 Yes 7 No

write the prime no program in c++?..

Answer / garima gupta

#include<iostream.h>
#include<conio.h>
#include<math.h>
class prime
{
private:
int i,j,j;
public:
void readn();
void display();
};
void prime::readn()
{
clrscr();
cout<<"enter no. of prime nos you want to display:"<<endl;
cin>>n;
}
void prime::display()
{
int flag;
for(i=2;i<n;i++)
{
flag=0;
for(j=2;j<=sqrt(i);j++)
{
if(i%j==0)
{
flag=1;break;
}
else(flag==0)
{
cout<<i<<" ";
}
}
}
}
void main()
{
prime p;
p.readn();
p.display();
getch();
}

Is This Answer Correct ?    10 Yes 18 No

write the prime no program in c++?..

Answer / adnan sheikh

#include<iostream.h>
#include<conio.h>

main()
{
int i,j,num;
cout<<"enter nay number";
cin>>num;
j=static_cast<int>(num/2);
for(int i=2;i<=j;i++)
{
if(!(num%i))
break;
}
if(i==(j+1))
cout<<"number is prime";
else
cout<<"number is not prime";
getch();
}

Is This Answer Correct ?    8 Yes 19 No

write the prime no program in c++?..

Answer / pramod k sharma

#include<iostream.h>
#include<conio.h>
main()
{
int n,i,f=1;
cout<<"enter any no to check prime";
cin>>n;
for(i=2;i<n;i++)
{
if(n%i==0)
k=2;
}
if(k==2)
cout<<"the no is not prime"<<endl;
else
cout<<"the no is prime";
}
getch();

Is This Answer Correct ?    14 Yes 32 No

Post New Answer

More C++ General Interview Questions

1)#include <iostream.h> int main() { int *a, *savea, i; savea = a = (int *) malloc(4 * sizeof(int)); for (i=0; i<4; i++) *a++ = 10 * i; for (i=0; i<4; i++) { printf("%d\n", *savea); savea += sizeof(int); } return 0; } 2)#include <iostream.h> int main() { int *a, *savea, i; savea = a = (int *) malloc(4 * sizeof(int)); for (i=0; i<4; i++) *a++ = 10 * i; for (i=0; i<4; i++) { printf("%d\n", *savea); savea ++; } return 0; } The output of this two programs will be different why?

5 Answers  


What is c++ virtual inheritance?

0 Answers  


Is arr and &arr are same expression for an array?

0 Answers  


what does the following statement mean? int (*a)[4]

0 Answers  


What is the difference between reference type and pointers.

4 Answers   HCL,


If you had the following code: int x = 23; int *y; y = &x; The instruction y++; does what?

2 Answers  


Explain object slicing in c++?

0 Answers  


What is the difference between function overloading and operator overloading?

0 Answers  


what are the characteristics of Class Members in C++?

0 Answers  


Is it possible for a member function to delete the pointer, named this?

0 Answers  


What is class invariant in c++?

0 Answers  


What is an Iterator class?

1 Answers  


Categories