check whether a no is prime or not.
Answers were Sorted based on User's Feedback
Answer / m.shanmuga sundaram,rjnsoftwar
void main()
{
int primeNo;
int i;
bool isPrime = false;
printf("Enter a number to check prime or not\n");
scanf("%d",&primeNo);
for(i = 2; i <= primeNo / 2; i++)
{
if(primeNo % i == 0)
{
isPrime = true;
break;
}
}
if(isPrime)
printf("The number is a prime number %
d\n",primeNo);
else
printf("The number is not a prime number %
d\n",primeNo);
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / paramjeet singh
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,c;
printf("enter any number\n");
scanf("%d",&i);
printf("you have entered=%d\n",i);
for(c=2;c<=i-1;c++)
{
if(i%c==0)
printf("this no.is not a prime number");
}
printf("this is prime number");
getch();
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / rama
#include<stdio.h>
main()
{
int n,i,r;
clrscr();
printf("Enter the positive integer value");
scanf("%d",&n)
i=2;
step1:
if(i<=sqrt(n))
{
r=n%i;
if(r==0)
{
printf("%d is not a prime",n);
goto end;
}
}
else
{
i++;
goto step1;
}
printf("%d is prime number",n);
end:
printf(" ");
}
Is This Answer Correct ? | 3 Yes | 2 No |
What do you mean by static variables?
Can I uninstall microsoft c++ redistributable?
Explain about templates of C++.
What is a forward referencing and when should it be used?
Differences between private, protected and public and give examples.
What are disadvantages of pointers?
What is the first name of c++?
Is rust better than c++?
What is #include c++?
i want the NIC programmer-B model papaer pattren, iwant the all model papers?
How to defines the function in c++?
Write a String class which has: 1) default constructor 2) copy constructor 3) destructor 4) equality operator similar to strcmp 5) constructor which takes a character array parameter 6) stream << operator
2 Answers HCL, Lehman Brothers, Zoomerang,