Skip to content

Commit 26d2856

Browse files
authored
Create Factors Finding.c
1 parent 72105d3 commit 26d2856

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* You are given a number N and find all the distinct factors of N.
2+
3+
Input:
4+
First-line will contain the number N.
5+
Output:
6+
In the first line print number of distinct factors of N.
7+
In the second line print all distinct factors in ascending order separated by space.
8+
Constraints
9+
1≤N≤106
10+
Sample Input 1:
11+
4
12+
Sample Output 1:
13+
3
14+
1 2 4
15+
Sample Input 2:
16+
6
17+
Sample Output 2:
18+
4
19+
1 2 3 6
20+
EXPLANATION:
21+
In the first example, all factors of 4 are 1, 2, 4.
22+
In the second example, all factors of 6 are 1, 2, 3, 6. */
23+
24+
#include <stdio.h>
25+
26+
int main(void) {
27+
28+
int n;
29+
scanf("%d",&n);
30+
int c=0;
31+
int a[n];
32+
33+
for(int i=1;i<=n;i++)
34+
{
35+
if(n%i==0)
36+
{
37+
a[c]=i;
38+
c++;
39+
}
40+
}
41+
printf("%d \n",c);
42+
for(int i=0;i<c;i++)
43+
{
44+
printf("%d ",a[i]);
45+
}
46+
47+
return 0;
48+
}

0 commit comments

Comments
 (0)