write the program for prime numbers?
Answers were Sorted based on User's Feedback
Answer / akhilesh singh(m.c.a-iisem ois
main()
{
int i,j=2,ch=0;
clrscr();
printf("\nENTER ANY NUMBER");
scanf("%d",&i);
while(j<=i/2)
{
if(i%j==0)
{
printf("%d IS NOT PRIME",i);
ch=1;
break;
}
else
{
j++;
}
}
if(ch==0)
{
printf("%d IS PRIME",i);
}
}
Is This Answer Correct ? | 1243 Yes | 384 No |
Answer / venkat reddy
#include<stdio.h>
main()
{
int i,n,count=0;
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");
}
Is This Answer Correct ? | 344 Yes | 155 No |
Answer / vasanth
This program is to check a given number is prime or not
(or) list the prime numbers in a given no.
For example, the user enter the no is 50. the program is
list the prime numbers in 50.
Is This Answer Correct ? | 402 Yes | 262 No |
Answer / vinay tiwari
try this u can find out all prime number between 2 and any
number entered by user .i write code in c# language but
concept remain same in any language.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication23
{
class Program
{
static void Main(string[] args)
{
int i=2, j, rem;
while (i <= 100)
{
for (j = 2; j < i; j++)
{
rem = i % j;
if (rem == 0)
break;
}
if (i == j)
Console.WriteLine(i);
i++;
}
}
}
}
Is This Answer Correct ? | 250 Yes | 136 No |
Answer / priyanka chauhan
// prime no series. //
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter the no: ");
scanf("%d",&n);
printf("\n");
for(i=1;i<=n;i++)
{
for(j=2;j<=i-1;j++)
{
if(i%j==0)
break;
}
if(j==i)
printf("%d ",j);
}
getch();
}
Is This Answer Correct ? | 173 Yes | 84 No |
Answer / naveen reddy
This is written in PL/SQL: TO check wether given number is prime or not
DECLARE
i number:=&i;
j number:=2;
ch number:=0;
BEGIN
WHILE(j<=i/2) loop
if mod(i,j)=0 then
dbms_output.put_line('not prime');
ch:=1;
exit ;
else
j:=j+1;
end if;
end loop;
if ch=0 then
dbms_output.put_line('prime number');
end if;
end;
Is This Answer Correct ? | 106 Yes | 23 No |
Answer / sham
int main()
{
int i,j,n,f=0;
printf("Enter the length\n");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
for(j=2;j<i;j++)
{
if((i%j)==0)
{
f=1;
break;
}
f=0;
}
if(f==0)
printf("%d ",i);
}
}
Is This Answer Correct ? | 180 Yes | 107 No |
Answer / gnanasekaran
int main()
{
int i,j,n,f=0;
printf("Enter the length\n");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
for(j=2;j<i;j++)
{
if((i%j)==0)
{
f=1;
break;
}
f=0;
}
if(f==0)
printf("%d ",i);
}
}
Is This Answer Correct ? | 139 Yes | 81 No |
Answer / arfu
#include<stdio.h>
int main()
{
int c,i,n;
c=0;
scanf("%d",&a);
for(i=2;i<a;i++)
if (n%i==0)
{
c=1;break;
}
if(c!=1)`("prime");
else printf ("not a prime");
}
Is This Answer Correct ? | 110 Yes | 89 No |
Answer / pritam neogi
#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 ? | 32 Yes | 16 No |
read an array and search an element
What is the function of ceil(X) defined in math.h do? A)It returns the value rounded down to the next lower integer B)it returns the value rounded up to the next higher integer C)the Next Higher Value D)the next lower value
wat is the difference between a definition and declaration? float y;---it looks like a declaration..but it s a definition.how?someone explain
can any one tel me wt is the question pattern for NIC exam
What is the process to create increment and decrement stamen in c?
Write a C/C++ program that connects to a MySQL server and checks intrusion attempts every 5 minutes. If an intrusion attempt is detected beep the internal speaker to alert the administrator. A high number of aborted connects to MySQL at a point in time may be used as a basis of an intrusion.
Write a program which take a integer from user and tell whether the given variable is squar of some number or not. eg: is this number is 1,4,9,16... or not
What does p mean in physics?
What is default value of global variable in c?
Why do we write return 0 in c?
Explain 'bit masking'?
What is #line in c?