Interview Question Multiples of a Number

We need to create a function that receives a paramter N and show all the number that meet the condition N=D*M, for example if N=24 the result is 8.

Constraints

Complexity of O(n) and N can be avery large number


#include <stdio.h>
#include <stdlib.h>
/** Solution **/
int solution(int n){
  int i,result=0;
  for (i = 1; i <= n; ++i){
   if(n%i==0)
   result++;
 }
 return result;
}

int main(int argc, char *argv[]){
printf("multiples: %i\n",solution(atoi(argv[1])));
return 0;
}
To compile this, save the code in multiples.c and compile using this command:
gcc -Wall multiples.c -o multi and execute like this ./multi 24

No comments: