write the program for prime numbers?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
why we use "include" word before calling the header file. is there any special name for that include??????
What Is The Difference Between Null And Void Pointer?
What is static function in c?
here is a link to download Let_Us_C_-_Yashwant_Kanetkar
how many keywords do C compile?
7 Answers Microsoft, Practical Viva Questions,
Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol
How many keywords (reserve words) are in c?
Tell me what is null pointer in c?
void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result for all case
What is array of structure in c?
which header file contains main() function in c?
17 Answers Google, HCL, TCS,
write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?