# Take integer and find divisors,prime? & how many divisors

1. Oct 8, 2015

### Md. Abde Mannaf

write a c programs Take integer and find all divisors/Factors , print is it prime or not? and how many divisors contain print it?
how to solve in one program and how many divisors/Factors
contains

my code:
Code (C):

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int number,i;
printf("This program calculate Divisors\n ");
printf("enter number= ");
scanf("%d",&number);
printf("Divisors are= ");
for(i=1;i<=number;i++)
{
if (number%i==0 )
{
printf("%4d",i);
}
}
getch();
return 0;
}

and

#include<stdio.h>

main()
{
int n, c = 2;

printf("Enter a number to check if it is prime\n");
scanf("%d",&n);

for ( c = 2 ; c <= n - 1 ; c++ )
{
if ( n%c == 0 )
{
printf("%d is not prime.\n", n);
break;
}
}
if ( c == n )
printf("%d is prime.\n", n);

return 0;
}

Last edited by a moderator: Oct 8, 2015
2. Oct 8, 2015

### cpscdave

What are the problems you are having?
Also in the future when posting code please use the
Code (Text):
['code'] ['/code'] (without the ') tags
it makes the code easier to read

3. Oct 8, 2015

### Svein

Just a comment: You do not have to check further than the square root of n. But since that probably is not an integer use:
Code (Text):

int maxcheck = ceil(sqrt(n));

4. Oct 8, 2015

### Md. Abde Mannaf

how to combine two program in one & how many number of divisor ?? print in program.