ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2253)
 C++ interview questions  C++ Interview Questions (1111)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (646)
Question
write the program for prime numbers?
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
 
Answer
# 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 ?    1238 Yes 383 No
Akhilesh Singh(m.c.a-iisem Ois
 
Answer
# 2
#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
Venkat Reddy
 
 
 
Answer
# 3
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 ?    401 Yes 262 No
Vasanth
 
Answer
# 4
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
Vinay Tiwari
 
Answer
# 5
// 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
Priyanka Chauhan
 
Answer
# 6
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 ?    105 Yes 23 No
Naveen Reddy
 
Answer
# 7
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
Sham
 
Answer
# 8
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
Gnanasekaran
 
Answer
# 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 ?    110 Yes 89 No
Arfu
 
Answer
# 10
#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
Pritam Neogi
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
What is the difference between typeof(foo) and myFoo.GetType()? Synergy 2
int main() { int i=1; switch(i) { case '1': printf("hello"); break; case 1: printf("Hi"); break; case 49: printf("Good Morning"); break; } return 0; }   3
write an algorithm and c program to add two 2x2 matrics   1
i want to have a program to read a string and print the frequency of each character and it should work in turbo c Persistent 3
what is op? for(c=0;c=1000;c++) printf("%c",c); Trigent 20
What is structure padding ? HP 3
what is printf Satyam 5
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10 Aspire 8
how can i get the output 54321 4321 321 21 1 in c programming........???? pls help......   8
Write a program to interchange two variables without using the third variable? Accenture 17
While compiling a c program,graphics header files are not including in my program..eg: <graphics.h>,what may be the problem...is there any environment settings exists.   2
What does the message "warning: macro replacement within a string literal" mean?   1
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com