how to find the given number is prime or not?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many types of functions are there in c?

576


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

1116


Differentiate between functions getch() and getche().

612


What is const volatile variable in c?

565


Write a program to implement queue.

653






What is calloc malloc realloc in c?

583


Is swift based on c?

626


What does d mean?

570


How can I discover how many arguments a function was actually called with?

626


What does the c preprocessor do?

609


Tell me when would you use a pointer to a function?

596


How do you convert strings to numbers in C?

699


Explain the advantages and disadvantages of macros.

612


how can i write a program that prints out a box such that whenever i press any key8(coordinate number) on the keyboard, the box moves.

1207


What does the error 'Null Pointer Assignment' mean and what causes this error?

732