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

can we implement multi-threads in c.

0 Answers  


What is the purpose of main( ) in c language?

0 Answers  


What are the functions to open and close the file in c language?

0 Answers  


A marketing company wishes to construct a decision table to decide how to treat clients according to three characteristics: Gender, City Dweller, and age group: A (under 30), B (between 30 and 60), C (over 60). The company has four products (W, X, Y and Z) to test market. Product W will appeal to female city dwellers. Product X will appeal to young females. Product Y will appeal to Male middle aged shoppers who do not live in cities. Product Z will appeal to all but older females.

2 Answers  


what does data structure mean?

8 Answers  






Explain how can I prevent another program from modifying part of a file that I am modifying?

0 Answers  


How do you search data in a data file using random access method?

0 Answers  


Difference between malloc() and calloc() function?

0 Answers  


PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM

0 Answers  


how do you programme Carrier Sense Multiple Access

0 Answers  


Is both getch() and getchar() functions are similar? if it is similar means why these two functions are used for same usage? if it is not similar means what is the difference?

1 Answers   Infosys,


Why c is procedure oriented?

0 Answers  


Categories