Friday, 23 August 2013

C check for number of divisors

C check for number of divisors

I am trying to find the number of divisors for each number from 1 to 100,
but i do not understand why it is not working. The compiler said that the
error is in line 18, 21 and 24.
#include <stdio.h>
#include <math.h>
#define N 100
int main()
{
float n;
float l
for (n=1; n<=N; n++) { //genertate a list of numbers
int a;
for (a=n; a>=n; a--) { //genarate a list of numbers less than "n"
l = n/a; //divide each number less than "n"
if (l == round(l)) { //see is "l" is a divisor of "n"
l=l+1; //if it finds a divisor it will add it
printf(n, l); //prints the number as well as the number of
divisors
}
}
}
}

No comments:

Post a Comment