Hi All,

I am writing a program to find the smallest positive integer that has n or more divisors. My program gives me correct answer for input values upto 4 but it produces erroneous answers for input values above 4. For example, it gives 10 as integer having 5 divisors.

Please point out errors or modifications. Below is the program:

``````/*program to find smallest positive integer that has n or more divisors excluding itself*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int n,i,posinteger=1,count=0,halfposinteger=0;
printf("enter the number of divisors");
scanf("%d",&n);
if(n<=4)
{
for(i=1;i<=n;i++)
{
posinteger*=i;
}
}
else
{
posinteger=8;
while(count!=n)
{
posinteger+=1;
halfposinteger=floor(posinteger/2);
for(i=1;i<=halfposinteger;i++)
{
if(posinteger%i==0)
{
count+=1;
}
}
}
}
printf("the smallest positive integer with %d divisors is %d",n,posinteger);
system("pause");
return 0;
}
``````

Hmm it looks to me like you forget to reset `count` after every `posinteger` check. If one particular integer has too few divisors, I assume you want to start counting divisors from zero on the next integer.

I hope this helps!

Regards,
Emil Olofsson