fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. int noOfFactors(int N){
  4. float x=sqrt(N);
  5. int c=2;
  6. for(int i=2;i<=(int)x;i++){
  7. if(N%i==0){
  8. c+=2;
  9. }
  10. }
  11. if(x==(int)x)
  12. {
  13. c=c-1;
  14. }
  15. return c;
  16. }
  17. main(){
  18. //Part A
  19. int n;
  20. printf("Enter a number :");
  21. scanf("%d", &n);
  22. int x=sqrt(n);
  23. printf("Factors of %d are :\n", n);
  24. for(int i=1;i<=x;i++){
  25. if(n%i==0){
  26. printf("%d, %d, ", i, n/i);
  27. }
  28. }
  29. printf("\n");
  30. //Part B
  31. int N;
  32. printf("Enter a number N :");
  33. scanf("%d", &N);
  34. int a=1;
  35. for(int i=1;i<=N;i++){
  36. if(noOfFactors(i)>noOfFactors(a))
  37. a=i;
  38. }
  39. printf("From 1 to %d the number containing maximum factors is %d", N, a);
  40.  
  41. }
  42.  
Success #stdin #stdout 0s 4720KB
stdin
75
50
stdout
Enter a number :Factors of 75 are :
1, 75, 3, 25, 5, 15, 
Enter a number N :From 1 to 50 the number containing maximum factors is 48