Hi All,

I am writing a program to find the number between 1 and 100 that has the greatest number of distinct divisors. Below is my code for the same. It is returning an erroneous answer, i.e. 8 for greatest number of distinct divisors and 4 as the number for which the greatest divisors are occurring:

Please point out modifications and mistakes. Thank you.

Code:/*program to find a number in the range 1 to 100 that has the largest number of distinct divisors*/ #include<stdio.h> #include<stdlib.h> #include<math.h> //this loop counts the number of distinct divisors int main() { int countstore[100]={0},result,i,j,num,halfnum,count=1,index; for(num=4;num<=100;num++) { halfnum=floor(num/2); count=1; for(i=2;i<=halfnum;i++) { if(num%i==0) { count+=1; } } for(j=1;j<=97;j++) { countstore[j]=count; } } //result stores the number of distinct divisors, index stores the number for which the greatest distinct divisors have been found result=0; for(i=1;i<=97;i++) { if(result<countstore[i]) { result=countstore[i]; index=i+3; } } printf("the integer between 0 and 100 with %d number of distinct divisors is %d",result,index); system("pause"); return 0; }