Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new

 Categories  >>  Software  >>  Programming Languages  >>  C

 C Interview Questions C++ Interview Questions VC++ Interview Questions Delphi Interview Questions Programming Languages AllOther Interview Questions
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?
# 61
#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

Re: write the program for prime numbers?
# 62
#include<stdio.h>
#include<conio.h>
int main()
{
int r,a,b,c=0;
printf("Enter the n value:");
scanf("%d",&r);
a=0;
while(a<=r)
{
b=1;c=0;
while(b<=a)
{
if(a%b==0)
c=c+1;
b++;
}
if(c==2)
printf("%d ",a);
a++;
}
getch();
return 0;
}

 Is This Answer Correct ? 0 Yes 0 No
Ankish Jaiswal

Re: write the program for prime numbers?
# 63
#include<stdio.h>

int main()
{
int c,i,n;
counter=0;
scanf("%d",&a);
for(i=2;i>a;i++)
if (n%i==0)
{
c=1;break;
}
if(c!=1) ("prime");
else print ("not a prime");
}

 Is This Answer Correct ? 0 Yes 0 No
Samson Mugambi

Re: write the program for prime numbers?
# 64
#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
Kiran Kumar Maharana

Re: write the program for prime numbers?
# 65
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num, i;
printf("enrer the value");
scanf("%d",&num);
i=2;
while(i<=num-1)
{
if(num%i==0)
{
printf("not a prime");
break;
}
i++;
}
if(i==num)
printf("prime");
getch();

}

 Is This Answer Correct ? 0 Yes 0 No
Love

Re: write the program for prime numbers?
# 66
#include<stdio.h>
#include<conio.h>

void main()
{
int x,y,z;
clrscr();
for(x=2; x<=50; x++)
{
for(y=2; y<x; y++)
{
if(x%y==0)
{
break;
}
}
if(x==y){
printf("%d\n",y);
}

}
getch();
}

 Is This Answer Correct ? 0 Yes 1 No
Chetan Mehra

Re: write the program for prime numbers?
# 67
plz write the pl/sql program for prime numbers? in simple way
dat can be understood easily....

 Is This Answer Correct ? 0 Yes 0 No
Nischal

Re: write the program for prime numbers?
# 68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public static void prime(int number)
{
for (int i = 1; i <= number; i++)
{
for (int j = 2; j <= number; j++)
{
if (i % j == 0)
{
if(i==j)
Console.WriteLine(i.ToString());
break;
}
}
}
}
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
prime(number);
}
}
}

 Is This Answer Correct ? 0 Yes 0 No
Lavanya

Re: write the program for prime numbers?
# 69
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i=2;
clrscr();
printf("\n entert a number");
scanf("%d",&num);
while(c<=num-1)
{
if(num%i==0)
{
printf("given number is not a prime number\n");
break;
}
i++;
}
if(i==num);
printf(given number is a prime number\n");
getch();
}

 Is This Answer Correct ? 0 Yes 0 No
Karthika

Re: write the program for prime numbers?
# 70
\*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
Anjana Rao .ch

  Question Asked @ Answers Other C Interview Questions How will you allocate memory to a double pointer ? 2 why should i select you? Wipro 20 who is the founder of c HP 19 void main() { for(; 0 ;) ... { printf("hello"); ... } getch(); } 1 SRUCTURE PROGRAMMING Wipro 3 what will be the result of the following program ? char *gxxx() { static char xxx[1024]; return xxx; } main() { char *g="string"; strcpy(gxxx(),g); g = gxxx(); strcpy(g,"oldstring"); printf("The string is : %s",gxxx()); } a) The string is : string b) The string is :Oldstring c) Run time error/Core dump d) Syntax error during compilation e) None of these IBM 2 a C prog to swap 2 no.s without using variables just an array? TCS 5 for example user gives input as " 20 or 20.0 or rs 20.0 or 20.00 or rs20 and so .. on " and the output should be stored as " rs.20.00 " in a variable 2 #define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); } 1 Can u return two values using return keyword? If yes, how? If no, why? 7 what is the use of a array in c 6 union { char ch[10]; short s; }test; test.s = 0xabcd; main() { printf("%d",ch[10]); } 3 For more C Interview Questions Click Here