write the program for prime numbers?
Answers were Sorted based on User's Feedback
Answer / pritam neogi
#include<stdio.h>
#include<conio.h>
void main()
{
int no,i;
clrscr();
printf(" Enter the Number U want to check:");
scanf("%d",&no);
i=2;
while(i<=no-1)
{
if(no%i==0)
{
printf(" %d is not Prime number",no );
// break;
}
i=i+1;
}
if(no==i)
printf("%d is a prime Number",no);
getch();
}
Is This Answer Correct ? | 24 Yes | 17 No |
Answer / arafat buet
#include<stdio.h>
int main()
{
int i,n,r;
printf("enter any number:");
scanf("%d",&n);
if(n==1)
printf("not prime\n");
for(i=2;i<n;i++)
{
r=n%2;
if(r==0)
{
printf("\nnot prime\n");
break;
}
}
if(i==n)
printf("prime\n");
return 0;
}
Is This Answer Correct ? | 24 Yes | 19 No |
Answer / tayyab ali
write the program to print prime numbers from 1 to 1000?
Is This Answer Correct ? | 16 Yes | 11 No |
Answer / karthik
#include<stdio.h>
#include<conio.h>
void main()
{
int n,flag;
clrscr();
printf("\n Enter prime no\n");
scanf("%d",&n);
for(int i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
if(flag==0)
printf("\n%d is not prime",n);
else
printf("\n %d is prime",n);
getch();
}
Is This Answer Correct ? | 21 Yes | 17 No |
Answer / paartha
include<stdio.h>
#include<conio.h>
void main()
{
int a,i , b,flag=0,no;
clrscr();
for(no=2;no<100;no++)
{
for(i=2;i<no;i++)
{
b=no%i;
if(b==0)
{
flag=1;
break;
}
else
{
flag=0;
}
}
if(flag!=1)
{
printf("\n%d",no);
}
}
getch();
}
Is This Answer Correct ? | 7 Yes | 3 No |
Answer / paps
#include<stdio.h>
void main()
{
int a=1,i,j,b,n;
printf("enter the range\n");
scanf("%d",&n);
printf("prime number series between 1 to %d:n");
printf("%d",a);
while(i<=n)
{
for(j=2;j<i;j++)
{
b=i%j;
if(b==0)
break;
}
if(i==j)
printf("%d",i);
i++;
}
getch();
}
Is This Answer Correct ? | 8 Yes | 4 No |
Answer / kiran
#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int main()
{
int tn=1,c=0,flag=0;;
cin>>tn;
for(int i=3; c!=tn;i++)
{for(int j=2;j<i;j++)
{
if(i%j==0){
flag=0; break;}
else flag=1;
}
if(flag)
{c++;
printf("%d,",i);
}
}
getch();
return 0;
}
Is This Answer Correct ? | 4 Yes | 0 No |
Answer / china
Find all primes not larger than N.
I think it is the most efficient algorithm to find all
primes no larger than N.
int main(void)
{
int i,j, N;
int *pPrimes;
int nPrimes, is_prime;
printf("Input N:");
scanf("%d", &N);
pPrimes = new int [N/2];
nPrimes = 0;
for(i = 2; i<=N; i++)
{
is_prime = 1;
for(j=0;j<nPrimes; j++)
if (i%pPrimes[j] == 0)
{
is_prime = 0; break;
}
if (is_prime)
{
pPrimes[nPrimes++] = i;
}
}
printf("%d primes found less than %d:\n", nPrimes, N);
for (i=0; i< nPrimes; i++)
printf("%d ", pPrimes[i]);
}
Is This Answer Correct ? | 80 Yes | 77 No |
Answer / pratibha
#include<stdio.h>
#include<conio.h>
void main()
{
int no,i,count=0;
clrscr();
printf("enter the no");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
if(no%i==0)
{
count=count+1;
}
}
if(count<=2)
{
printf("this is prime no");
}
else
{
printf("this is not prime");
}
getch();
}
Is This Answer Correct ? | 17 Yes | 14 No |
import java.*;
class prime
{
public static void main(String args[])
{
int number=__;//"you wish to check ";
int flag=0;
for(i=2;i<=(int)(Math.sqrt(number));i++)
{
if(number%i==0)
{
System.out.println("Not a Prime Number");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Prime Number");
}
}
Is This Answer Correct ? | 12 Yes | 9 No |
Explain the difference between the local variable and global variable in c?
Why we write conio h in c?
What does c mean?
How to print "Hi World" without using semi colon?
WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary display all contents?
6 Answers Finite Infotech, Lovely Professional University, Wipro,
prog for 1st five prime numbers in 2^x - 1
write a c program that if the given number is prime, and their rearrangement(permute) of that number is also prime. Ex: Input is "197" is prime Output: 791,917,179 is also prime. Please any one tell me tha code for that
Explain how does free() know explain how much memory to release?
What does it mean when the linker says that _end is undefined?
how can I convert a string to a number?
Define a structure to store the record of library. The record must consist of at least following fields: Title, Author, Edition, Price, Publisher, and Category. -Define functions authorSearch ( ), TitleSearch ( ) and CategorySearch ( ) to search a book with respect to author, title and category. [There can be more than one book, written by one author, in one category]
how do you programme Carrier Sense Multiple Access