division - C check for number of divisors -
i trying find number of divisors each number 1 100, not understand why not working. compiler said error in line 18, 21 , 24.
#include <stdio.h> #include <math.h> #define n 100 int main() { float n; float l (n=1; n<=n; n++) { //genertate list of numbers int a; (a=n; a>=n; a--) { //genarate list of numbers less "n" l = n/a; //divide each number less "n" if (l == round(l)) { //see "l" divisor of "n" l=l+1; //if finds divisor add printf(n, l); //prints number number of divisors } } } }
here warning compiler gave:
ks-macbook-pro:~ kyle$ gcc /users/kyle/app-tests/c/divisors.c /users/kyle/app-tests/c/divisors.c: in function 'main': /users/kyle/app-tests/c/divisors.c:18: error: nested functions disabled, use -fnested-functions re-enable /users/kyle/app-tests/c/divisors.c:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'for' /users/kyle/app-tests/c/divisors.c:21: error: 'l' undeclared (first use in function) /users/kyle/app-tests/c/divisors.c:21: error: (each undeclared identifier reported once
/users/kyle/app-tests/c/divisors.c:21: error: each function appears in.) /users/kyle/app-tests/c/divisors.c:24: error: incompatible type argument 1 of 'printf'
float l
missing semicolon here
printf(n, l);
that's not how printf
used, use instead:
printf("%f, %f", n, l);
this should solve compile issue.
Comments
Post a Comment