write the program for prime numbers?

Answers were Sorted based on User's Feedback



write the program for prime numbers?..

Answer / vivek s

{
int n;
printf("\n Enter The Number\n");
scanf("%d",&n);
if(n>3 && n!=5 && n!=7)
if(n%2!=0)
if(n%3!=0)
if(n%5!=0)
if(n%7!=0)
printf("\n\n %d is a prime number",n);
else
printf("\n\n %d is not a prime number",n);
else
printf("\n\n %d is not a prime number",n);
else
printf("\n\n %d is not a prime number",n);
else
printf("\n\n %d is not a prime number",n);
else
printf("\n\n %d is a prime number",n);

getch();
}

Is This Answer Correct ?    2 Yes 2 No

write the program for prime numbers?..

Answer / harpreet dhillon

#include<stdio.h> \\harpreetdhillon7@gmail.com
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("enter any number which you want to check");
scanf("%d",&n);
for(i=2;i<=n-1;i++)
{
if(n%i==0)
{
printf("not a prime number\n");
break;
}
else
{
printf("prime number\n");
break;
}
}

Is This Answer Correct ?    2 Yes 2 No

write the program for prime numbers?..

Answer / azka sumbel

namespace prime_381
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int a;
int result;
int i, j;

private void button1_Click(object sender, EventArgs
e)
{

a = Convert.ToInt32(textBox1.Text);
prime();
textBox1.Clear();
textBox1.Focus();

}
int flag;
public void prime()
{
flag = 1;

for (i = 2; i <= a / 2; i++)
{
if (a % i == 0)
flag = 0;
}
if (flag == 1)
MessageBox.Show("Prime.");
else
MessageBox.Show("not Prime");
}
}
}

Is This Answer Correct ?    1 Yes 1 No

write the program for prime numbers?..

Answer / pran pratim

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,i,count=0;
cout<<"Enter the number::";
cin>>num;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0)
{
cout<<"The number is Prime";
}
else
cout<<"The number is Composite";
getch();
}

Is This Answer Correct ?    2 Yes 2 No

write the program for prime numbers?..

Answer / paul

#include <stdio.h>
#include<stdlib.h>

#define TRUE 1
#define FALSE 0

int main()
{
int i,x,prime = TRUE;
printf(".:Modified Prime Program:.\n\n");
printf("Enter a number: ");
scanf("%d",&x);
printf("\nNUMBER\t REMARKS\n");
do
{
for(i=2;i<x;i++)
if(x%i==0)
{
prime=FALSE;
break;
}
if (prime=1 && (!(i<=x/2)))
printf("%d\t PRIME\n",x);
else
printf("%d\t COMPOSITE\n",x);
}
while (x-=1);
system ("pause");
return 0;
}

Is This Answer Correct ?    0 Yes 0 No

write the program for prime numbers?..

Answer / manish kumar

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 ?    0 Yes 0 No

write the program for prime numbers?..

Answer / ashwini kumar nayak

#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
int c,i,n;
c=0;
printf("Enter the number");
scanf("%d",&n);
if(n==1)
printf("Number is the special number");
else
{
for(i=2;i<n;i++)
if (n%i==0)
{
c=1;break;
}
if(c!=1)
printf("prime");
else
printf ("not a prime");
}
getch();

}

Is This Answer Correct ?    0 Yes 0 No

write the program for prime numbers?..

Answer / ankish jaiswal

#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

write the program for prime numbers?..

Answer / samson mugambi

#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

write the program for prime numbers?..

Answer / love

#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

Post New Answer

More C Interview Questions

List the variables are used for writing doubly linked list program.

0 Answers   Infosys, Wipro,


any "C" function by default returns an a) int value b) float value c) char value d) a & b

0 Answers  


Is the below things valid & where it will be stored in memory layout ? static const volatile int i; register struct { } ; static register;

2 Answers   Bosch,


code for concatination of 2 strings with out using library functions?

3 Answers  


Write a program to print fibonacci series without using recursion?

0 Answers  






What is the difference between int main and void main in c?

0 Answers  


what are advantages of U D F?

1 Answers   Google,


an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational

0 Answers  


Why do we use main function?

0 Answers  


write a program to generate address labels using structures?

0 Answers   SJC,


What does dm mean sexually?

0 Answers  


how to copy a string without using c function

5 Answers  


Categories