Beginner being fucked by pointers in C

0 Alex Carter · August 12, 2015
Ok, guys, this is the assignment:

Write a function in C which counts and returns the number of divisors of some number.
If the given number is 7, the function needs to return 2 because 7 can be divided by 1 and 7. 
I know the logic, but, pointers are confusing me here...

Post a Reply

Replies

Oldest  Newest  Rating
0 Alex Carter · August 13, 2015
#include <stdio.h>

int  delilac(int broj)
{
int i;
int sir = 0;

for(i=1;i<=broj;i++)
{
if(broj % i == 0)
{
sir++;
}
}

return sir;





}


int main()
{
int broj;




scanf("%d", &broj);
delilac(broj);

printf("Broj %d ima %d delilaca\n", broj, delilac);

return 0;
}

 I don't know why this isn't working..
+1 c student · August 13, 2015
you're not returning your function's value into anything.
printf("Broj %d ima %d delilaca\n", broj, delilac(broj));
  • 1

C

106,959 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator