Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
 Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM

 Categories >> Software >> Programming Languages >> C

 C Interview Questions (2247) C++ Interview Questions (1103) VC++ Interview Questions (342) Delphi Interview Questions (510) Programming Languages AllOther Interview Questions (644)
Question
`write the program for prime numbers?`
Question Submitted By :: Aaaa
I also faced this Question!!     Rank Answer Posted By

Re: write the program for prime numbers?
# 1
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 ? 1235 Yes 382 No
Akhilesh Singh(m.c.a-iisem Ois

Re: write the program for prime numbers?
# 2
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 ? 399 Yes 260 No
Vasanth

Re: write the program for prime numbers?
# 3
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 ? 249 Yes 136 No
Vinay Tiwari

Re: write the program for prime numbers?
# 4
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 ? 309 Yes 308 No
Biswa

Re: write the program for prime numbers?
# 5
#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 ? 340 Yes 155 No
Venkat Reddy

Re: write the program for prime numbers?
# 6
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 ? 178 Yes 107 No
Sham

Re: write the program for prime numbers?
# 7
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 ? 137 Yes 81 No
Gnanasekaran

Re: write the program for prime numbers?
# 8
// 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 ? 169 Yes 84 No
Priyanka Chauhan

Re: write the program for prime numbers?
# 9
#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 ? 109 Yes 89 No
Arfu

Re: write the program for prime numbers?
# 10
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
China

  Question Asked @ Answers Other C Interview Questions what will be the out put. #include void main() { printf("Output:"); printf(1+"vikashpatel"); }//output: ikashpatel 1 what is the difference between procedure oriented and object oriented progaming language 1 Write code for initializing one dimentional and two dimentional array in a C Program? Deshaw 5 what is the difference between embedded c and turbo c ? 1 52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2? TCS 22 pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used. Persistent 4 How to find the usage of memory in a c program Infosys 1 IS it possible to define a zero sized array in c.if it is possible how can the elements of that array can be accessed.array index starts from zero,if it is possible to define zero sized array how can be its first element can be accesseed. TCS 5 convert 12345 to 54321 withoutusing strig 5 write a c prog for removing duplicate character from an array and sorting remaining elements using a single array 1 what is the diff between the printf and sprintf functions?? and what is the syntax for this two functions ?? 5 what is software? wipro 5 For more C Interview Questions Click Here