write the program for prime numbers?

Answers were Sorted based on User's Feedback



write the program for prime numbers?..

Answer / d.sukumar

void main()
{
int i,k;int count=0;
int n;
printf("enter a no");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
k=n%i;
if(k==0)
{
count++;
}
}
if(count==1)
printf("prime");
else
printf("not prime");
}

Is This Answer Correct ?    1 Yes 0 No

write the program for prime numbers?..

Answer / awais

A PROG TO CHECK ANY NUMBER IS PRIME OR NOT BY USING IF ELSE STATEMENT
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x;
printf("enter number");
scanf("%d",&x);
if(x==1)
{
printf("the number is neither composite nor prime");
}
else if(x==2)
{
printf("the number is prime");
}
else if(x%2==0)
{
printf("the number is not prime");
}
else if(x%2!=0)
{
printf("the number is prime");
}
getch();
}

Is This Answer Correct ?    1 Yes 0 No

write the program for prime numbers?..

Answer / pavankumar

void main()
{
int i=2;
int count=0;
int n;
printf("enter a no");
scanf("%d",&n);
for(i=2;i<n/2;i++)
{
if(n%i==0)
{
count++;
}
if(count>1)
{
prinf("prime");
else
printf("not prime");
}

Is This Answer Correct ?    1 Yes 0 No

write the program for prime numbers?..

Answer / pawan kumar

#include<stdio.h>

int main(){

int num,i,count=0;
printf("Enter a number: ");
scanf("%d",&num);
for(i=2;i<=num/2;i++){
if(num%i==0){
count++;
break;
}
}
if(count==0 && num!= 1)
printf("%d is a prime number",num);
else
printf("%d is not a prime number",num);
return 0;
}

Is This Answer Correct ?    1 Yes 0 No

write the program for prime numbers?..

Answer / anmol

#includesd

Is This Answer Correct ?    1 Yes 0 No

write the program for prime numbers?..

Answer / adhiyamaan

#include<stdio.h>
#include<conio.h>
{
int num,i;
printf("enter the number:");
scanf("%d",&num);
for(i=2;i<=num-1;i++)
{
if(num%i==0)
{
printf("NOT PRIME");
break;
}
}
if(i==num)
{
printf("PRIME");
}
getch();
}

Is This Answer Correct ?    1 Yes 0 No

write the program for prime numbers?..

Answer / kiran kumar maharana

#include<iostream.h>
#include<conio.h>
int prime(int);
void main()
{
int n;
cout<<"enter a no.";
cin>>n;
int x;
x=prime(n);
if(x==1)
cout<<"prime";

else
cout<<"not a prime no.";

}
int prime(int n)
{
int i,count=0;
if(n<2)
{
return 0;
}
else
{for(i=2;i<n;i++)

{
if(n%i==0)
{
count++;
}
}
if(count>=1)
{

return 0;

}
else
return 1;}

}

Is This Answer Correct ?    1 Yes 0 No

write the program for prime numbers?..

Answer / anjana rao .ch

\*Write a program wither given number is prime or not */
\*I think it is different to others (BY ANJAN)*/
#include<stdio.h>
main()
{
int n,a=3;
printf("Enter Number");
scanf("%d",&n);
if(n==2)
{
printf("Given Number is PRIME");
exit (0);
}
if(n==3)
{
printf("Given Number is PRIME");
exit (1);
}
if(n%2==0)
{
printf("Given Number is NOT PRIME");
exit (2);
}
while(a<=n/2)
{
if(n%a==0)
{
printf("Given Number is NOT PRIME");
exit (3);
}
a=a+2;
}
printf("Given Numbr is PRIME");
}

Is This Answer Correct ?    1 Yes 0 No

write the program for prime numbers?..

Answer / santhoshi

main()
{
for(int i=1;i<100;i++)
{
count=0;
for(j=1;j<=100;j++)
{
if(i%j==0)
{
count++;
}
}
if(count==2)
{
printf(i);
}
}
getch();
}

Is This Answer Correct ?    12 Yes 12 No

write the program for prime numbers?..

Answer / sikendar kumar

#include<stdio.h>
#include<conio.h>

main()
{
int i,n,count=0;
clrscr();
printf("enter a no.");
scanf("%d",&n);
for(i=2;i<=n;i++)

{
if(n%i==0)
{
count++;
}
}
if(count==1)
{
printf("not prime no.");

}
else
printf("prime");
return 0;
}

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More C Interview Questions

State the difference between realloc and free.

0 Answers   Aricent,


Why doesnt that code work?

0 Answers  


What’s the special use of UNIONS?

0 Answers   ADP,


What are the types of type specifiers?

0 Answers  


Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

0 Answers  






How can you read a directory in a C program?

0 Answers  


int main() { int i=-1,j=-1;k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d%d%d%d%d",i,j,k,l,m); }

3 Answers   HCL,


Does c have function or method?

0 Answers  


Write a program to print this triangle: * ** * **** * ****** * ******** * ********** Don't use printf statements;use two nested loops instead. you will have to use braces around the body of the outer loop if it contains multiple statements.

6 Answers   Wipro,


What is the scope of local variable in c?

0 Answers  


what is the use of c program?

4 Answers   Synergy, Web Synergies,


What is sorting in c plus plus?

0 Answers  


Categories