write the program for prime numbers?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
State the difference between realloc and free.
Why doesnt that code work?
What’s the special use of UNIONS?
What are the types of type specifiers?
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?
How can you read a directory in a C program?
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); }
Does c have function or method?
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.
What is the scope of local variable in c?
what is the use of c program?
4 Answers Synergy, Web Synergies,
What is sorting in c plus plus?