answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

void main()

{

int n,i,r,count=0;

clrscr();

printf("Enter a number");

scanf("%d",&n);

for(i=2;i<n;i++)

{

r=n%i;

if(r==0)

{

count++;

break;

}

}

if(count==0 && n!=1)

{

printf("It is a Prime number");

}

else

{

printf("It is not a prime number");

}

getch();

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

#include<stdio.h>

#include<conio.h>

void main()

{

int num,i;

clrscr();

printf("\nEnter any number:");

scanf("%d",&num);

i=2;

while(i<=num-1)

{

if(num%i==0)

{

printf("\nNumber is not prime.");

break;

}

i++;

}

if((i==num)(num==1))

printf("\nNumber is prime.");

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include
#include
void main()
{
int j,n;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
j=2;
while(j<=n)
{
if(n%j==0)
break;
j++;
}
if(j==n)
printf("%d is Prime",n);
else
printf("%d is Not Prime",n);
getch();
}

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

#include<stdio.h>

// returns true if num is non-zero and is equal to

// the sum of all its proper positive divisors.

bool is_perfect (unsigned num)

{

unsigned div=0, sum=0;

while(++div<num)

if(num%div==0)

sum+=div;

return num && num==sum;

}

void main()

{

unsigned n;

printf("Enter a number: ");

scanf("%d",&n);

if(is_perfect(n))

printf("The number %d is perfect\n", n);

else

printf("The number %d is not perfect\n", n);

}

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

#include<stdio.h>

bool is_prime (const unsigned int num) {

if (num<2) return false;

if (!(num%2)) return num==2;

unsigned int max_factor = sqrt (num) + 1;

unsigned int factor;

for (factor=3; factor<max_factor; factor+=2)

if (!(num%factor)) return false;

return true;

}

int main (void) {

printf ("Input a number: ");

unsigned int num;

scanf("%d", num);

if (num<0) num*=-1; /* ensure num is positive */

if (is_prime (num))

printf ("The number is prime\n");

else

printf ("The number is composite\n");

return 0;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program that checks whether given number is perfect or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Make a C programming that displays the first four perfect numbers?

create a program that iterates until it finds a perfect number, then store that perfect number into an array. Continue iterating until you find three more. Then, you have an array of four perfect numbers.


How do you write a C program to Print 1st 30 Perfect numbers starting from 0?

int i; for (i=2; i&lt;=30; i+=2) printf ("%d\n", i);


The max number of functions you have used in a c program?

There is no limit to the number of functions you can have in a program. The only practical limit is dependant upon the amount of memory you have available in order to load the compiled program, whether it has 4 functions or 4 trillion functions. If the program makes use of dynamic libraries, then the amount of available memory reduces accordingly.


How do you write a C program to check whether the number is odd or even Ps-using DEV complier?

To write a C program to determine if something is odd or even you need to be a programmer. To write a program in C is complicate and only done by programmers.


Write Shell programme to check number is perfect or not?

Write a shell program to test whether the given number is a perfect number or not.#include#includevoid main(){int n,s=0,i;clrscr()printf("s=");scanf("%d",&n);for(i=0;i

Related questions

Write a program number as a peimeter and checks whether it is perfect or not in java?

class perfect{public static void main(int n) // input as parameter{int a=0;for(int i=1;i


Write a c program using while loop to accept a number check and display message whether number is perfect or not?

The program is here guys.......... //Finding whether the given number is perfect or not //Starts here #include&lt;stdio.h&gt; void main() { int i=1,temp=0,number; scanf("%d",&amp;number); while(i&lt;=number/2){ if(number%i==0) temp+=i; i++; } if(temp==number) printf("Its a perfect number"); else printf("Its not a perfect number"); } //ends here


Could you write a assembly language program in tasm To check whether a given number present in a sequence of given memory location containing the string to be checked in 8086?

8086 assembly language program to check wether given number is perfect or not


What is a number that is odd and it's a perfect number?

It is unknown whether an odd perfect number actually exists. If an odd perfect number exists it will be extremely large, that is in excess of 10300.


Write a program By using if else statement to read a number and check whether it is positive or negative?

write a c++program by using if statement to read a number and check whether it is positive or negative


Is 495 a perfect number?

No, it isn't. In fact, it is not known whether are odd perfect numbers exist. The first perfect numbers are 6, 28, 496, and 8128.


Is 31 a perfect number?

No. The only perfect numbers less than 100 are 6 and 28. All known perfect numbers are even - it is unknown whether there are odd perfect numbers.


How can I tell whether a number is a square number?

You can tell whether a number is a square number by looking at the last digit. A perfect square number ends with either 1, 4, 5, 6, 9 or 00.


Make a C programming that displays the first four perfect numbers?

create a program that iterates until it finds a perfect number, then store that perfect number into an array. Continue iterating until you find three more. Then, you have an array of four perfect numbers.


What are perfact numbers?

If the sum of all a number's factors (factors that are smaller than the number itself) is equal to the number itself, the number is said to be "perfect". For example, the factors of 6 (excluding 6 itself) are 1, 2, and 3; and the sum of these numbers is exactly 6. The smallest perfect numbers are 6, 28, 496, 8128. It isn't known whether the set of perfect numbers is finite or infinite. Also, it isn't known whether there are any odd perfect number; all known perfect numbers are even.


Is 32 an almost perfect number?

Yes. The only known almost perfect numbers are the powers of 2. 32 = 2^5 is an almost perfect number. It has not yet been proved whether {x: x = 2^n for n in N} = {x: x is an almost perfect number}.


Whether frequent flyer number is same as skyward number?

Yes, Skyward is Emirates frequent flyer program.