I have written the following code which contans two functions
1.To find the number of divisors of a number
2.To store the divisors in an array.
#include <stdio.h>
int numOfDivisors(int n)
{
int i, numOfDivisors=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
numOfDivisors++;
}
}
return numOfDivisors;
}
void storeDivisors(int count,int divisors[],int n)
{
int i,j;
for(i=1,j=0;i<=n,j<count;i++,j++)
{
if(n%i==0)
{
divisors[j]=i;
}
}
}
int main()
{
int n,m,a,i;
scanf("%d %d %d",&n,&m,&a);
int count1=numOfDivisors(n);
int count2=numOfDivisors(m);
/*printf("%d %d",count1,count2);*/
int divisors1[count1],divisors2[count2];
storeDivisors(count1,divisors1,n);
storeDivisors(count2,divisors2,m);
for(i=0;i<count1;i++)
{
printf("%d\t%d\n",divisors1[i],divisors2[i]);
}
return 0;
}
This is just part of a bigger code I need to make.
I am getting junk values. What am I doing wrong?