ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  C++ General
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
write the prime no program in c++?
 Question Submitted By :: Vijay_it4all
I also faced this Question!!     Rank Answer Posted By  
 
  Re: write the prime no program in c++?
Answer
# 1
#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 ?    3 Yes 5 No
Md.irfan(rourkela)
 
  Re: write the prime no program in c++?
Answer
# 2
/*To check whethere Entered no. is PRIME or NOT*/
  #include<iostream.h>
  #include<conio.h>
  main()
  {
		int num,i;
		clrscr();
		cout<<"Enter the any no.="<<"\n";
		cin>>num;
		for(i=2;i<=num;i++)
		{
			if(num%i==0)
			{
				break;
			}
		}
		if(i==num)
		{
			cout<<"The number entered is a 
PRIME no.";
		}
		else
		{
			cout<<"The number entered is NOT a 
PRIME no.";
		}
		getch();
  }
 
Is This Answer Correct ?    4 Yes 3 No
Swapnil
 
 
 
  Re: write the prime no program in c++?
Answer
# 3
#include<stdio.h>
#include<conio.h>
main()
{
int n,s=0,i;
clrscr();
printf("Enter the number\n");
scanf("%d",&n);
for(i=2;i<n/2;i++)
{
if(n%i==0)
 s++;
}
     if(s>=1)
     printf("%d is not prime",n);
     else
     printf("%d is prime",n);
     getch();
}
ill execute it .it's cent percent correct.
 
Is This Answer Correct ?    1 Yes 0 No
Indu
 
  Re: write the prime no program in c++?
Answer
# 4
#include <iostream>
using namespace std;

void main()
{
	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;
			 
}
 
Is This Answer Correct ?    0 Yes 0 No
Prits
 

 
 
 
Other C++ General Interview Questions
 
  Question Asked @ Answers
 
Write the program for fibonacci in c++?  3
What is a pure virtual function? Why is it represented as = 0...how is the internal implementation for the same CTS3
Difference between Overloading and Overriding? HP4
What is the difference between = and == in C? Intel8
What is the difference between a copy constructor and an overloaded assignment operator? Microsoft3
What is the Difference between "C structure" and "C++ structure"?  4
What does '\r' and '\b' mean? Please explain with example.  2
What is Object Oriented programming.what is the difference between C++ and C? Infosys5
what is static function Patni2
How do I open binary files?  1
Find the second maximum in an array? HCL2
Difference between static global and global? Symphony8
What C++ libraries are you proficient with? Google1
Can inline functions have a recursion? Give the reason?  1
In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. GE3
Write any small program that will compile in "C" but not in "C++"?  3
Why would you make a destructor virtual? Lehman-Brothers3
Implement strncpy  2
Describe functional overloading? HP3
Which of the Standard C++ casts can be used to perform a ?safe? downcast: a) reinterpret_cast b) dynamic_cast c) static_cast d) const_cast Quark1
 
For more C++ General Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com