write the program for prime numbers?

Answers were Sorted based on User's Feedback



write the program for prime numbers?..

Answer / karthikeyan murugesan

hi u can try this one for prime number and generation ::
#include<stdio.h>
void main()
{
int n,i=1,j,c;
scanf("%d",&n);
while(i<=n)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
{
printf("%d",i);
i++;
}
}
getch();
}

Is This Answer Correct ?    0 Yes 1 No

write the program for prime numbers?..

Answer / dinesh kumar.s

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,a;
clrscr();
printf("program created by dinesh mca anna university\n");
printf("enter the number\n");
scanf("%d",&a);

j=a;

if( a%2==0 || a%3==0 )
{
for(i=2;i<=a;i++)
if(a%i==0)
if (i==j)
{
printf("prime number");
break;
}

else
{
printf("not");
break;
}
}
else
{
printf("prime number");

}

getch();
}

Is This Answer Correct ?    1 Yes 2 No

write the program for prime numbers?..

Answer / farhana parvin sunny

#include<stdio.h>

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 ?    1 Yes 2 No

write the program for prime numbers?..

Answer / sujeet

#include<iostrream.h>
#include<conio.h>
void main()
{
int n;
cin>>n;
if(n==2)
{
cout<<"no is prime")
if(n%2!=0)
{
if(n%3!=0)
{
if(n%5!=0)
{
if(n%7!=if(n%2!=0)
{
0)
{
if(n%11!=0)
{
if(n%13!=0)
{
cout<<"no is prime ";
}
}
}
}
}
}
}
}
}
getch()
}

Is This Answer Correct ?    1 Yes 2 No

write the program for prime numbers?..

Answer / avinash

#include<stdio.h>
main()
int 1
{
printf("enter a number");
scanf("%d",1)
}
printf("The number is a prime number");
else
printf("The number is not a prime number");
}

Is This Answer Correct ?    1 Yes 2 No

write the program for prime numbers?..

Answer / nandhini

#include<stdio.h>
int main()
{
int i,j,n,count=0;
printf("Enter the number:");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
for(j=2;j<=i;j++)
{
if(i%j==0 && i/1==i)
{
count=count+1;
}
}
if(count==1)
{
printf("\n%d",i);
}
count=0;
}
}

Is This Answer Correct ?    0 Yes 1 No

write the program for prime numbers?..

Answer / chetan mehra

#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

write the program for prime numbers?..

Answer / sreejesh1987

//Output primes upto limit n(Give n>2)
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("\t\t\tPRIME NUMBERS\n");
printf("Enter n:");
scanf("%d",&n);
printf("\n\t2");
for(i=3;i<=n;i++)
for(j=2;j<i,i%j!=0;j++)
if(i-1==j)
printf("\n\t%d",i);
getch();
}

Is This Answer Correct ?    11 Yes 13 No

write the program for prime numbers?..

Answer / mudassir shakil

using System;
class Prime_Checker
{
int i;
int counter=0;
int n;
Console.WriteLine("Enter the number");
n=int.Parse(Console.ReadLine());
for(i=2;i<=n;i++)
{
if(n%i==0)
{
counter=1;
}
if(counter=0)
{
Console.WriteLine("No is prime");
}
else
{
Console.WriteLine("No is not prime");
}
}
}

Is This Answer Correct ?    1 Yes 3 No

write the program for prime numbers?..

Answer / mamoon

#include<iostream.h>
#include <math.h>

void main()
{
int number;
cout<<" --------------------------------------------
-"<<endl;
cout<<" Enter a number to find if its a prime
number "<<endl;
cout<<" --------------------------------------------
-"<<endl;
cin>>number;
bool a =true;

for(int i=2;i<sqrt(number);i++) //check
untill the square root
{

if(number%i==0) // if it is
divisible it is non prime
{
a=false;
break;
}
}


if(a==false)
cout<<number<<" \nis not a prime number"<<endl;
else
cout<<number<<" \nis a prime number"<<endl;

}

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Interview Questions

what is the use of c program?

4 Answers   Synergy, Web Synergies,


What are the features of c languages?

0 Answers  


What's the right way to use errno?

0 Answers  


wht is the difference between KPO and BPO ?

2 Answers   Accenture, BPO, HCK, HCL, Infosys,


how can i calculate mean,median,mode by using c program

1 Answers   HCL,






what is use of malloc and calloc?

0 Answers  


How can I invoke another program or command and trap its output?

0 Answers  


What is switch in c?

0 Answers  


write a program to display reverse of a number using for loop?

14 Answers  


do u print this format '(((())))'. This brackets is based on user input like 4 or 5 or 6,without using any loop's?

1 Answers   Oracle,


read a number & print all its devisors using c-program?

3 Answers  


main() { char as[] = "\\0\0"; int i = 0; do{ switch( as[i++]) {case '\\' : printf("A"); break; case 0 : printf("B"); break; default : printf("C"); break; }} while(i<3); }

4 Answers   Vector, Vector India,


Categories