how to find the given number is prime or not?

Answers were Sorted based on User's Feedback



how to find the given number is prime or not?..

Answer / rahul tiwari

main()
{
int n,ctr=2,flag=0;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=n/2;ctr++)
{
if(n%ctr==0)
{
flag=1;
break;
}
}
if(flag==1)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
flag=9
getch();
}

Is This Answer Correct ?    8 Yes 7 No

how to find the given number is prime or not?..

Answer / rajamanickam.m

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,flag=0,ctr;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=sqrt(n);ctr++)
{
if(n%ctr==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
getch();
}

Is This Answer Correct ?    3 Yes 2 No

how to find the given number is prime or not?..

Answer / shrikanth s.hallikhed

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,flag=0,ctr;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=sqrt(n);ctr++)
{
if(n%ctr==0)
{
flag=1;
break;
}
}
if(flag==1)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
getch();
}

Is This Answer Correct ?    3 Yes 3 No

how to find the given number is prime or not?..

Answer / arunkumar mt

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n,flag=0;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("given number %d is prime",n);
}
else
{
printf("given number %d is not prime",n);
}
getch();
}

Is This Answer Correct ?    2 Yes 3 No

how to find the given number is prime or not?..

Answer / shweta

#include<stdio.h>
#include<conio.h>
void main()
{
int n,ctr=2,flag=0;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=n/2;ctr++)
{
if(n%ctr==0)
{
flag=1;
break;
}
}
if(flag==1)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
flag=0;
getch();
}

Is This Answer Correct ?    2 Yes 5 No

how to find the given number is prime or not?..

Answer / amit kumar

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,flag=0,ctr;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=sqrt(n);ctr++)
{
if(n%ctr==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
getch();
}

Is This Answer Correct ?    2 Yes 5 No

Post New Answer

More C Interview Questions

What are the preprocessor categories?

0 Answers  


What is pragma c?

0 Answers  


What is a method in c?

0 Answers  


What is Generic pointer? What is the purpose of Generic pointer? Where it is used?

3 Answers  


Write a code to remove duplicates in a string.

0 Answers   Expedia,






5. What kind of sorting is this: SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort

2 Answers   Accenture,


What are the benefits of c language?

0 Answers  


Explain what are reserved words?

0 Answers  


main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } what is the output?

9 Answers   Ramco,


What is a function simple definition?

0 Answers  


can u write a program in C, which does not use = (eqaul)or any arithmatic assignment(like -=,+=,*= etc) operator to swap to number?

2 Answers  


. Write a program to get a string and to convert the 1st letter of it to uppercase

2 Answers   HTC,


Categories