-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFactor.C
More file actions
85 lines (74 loc) · 2.25 KB
/
Factor.C
File metadata and controls
85 lines (74 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* @file Factor.C
* @brief Finds and prints all factors of a given number.
*
* @author Amey Thakur
* GitHub: https://github.com/Amey-Thakur
* @author Mega Satish
* GitHub: https://github.com/msatmod
* @author Hasan Rizvi
* GitHub: https://github.com/rizvihasan
*
* @project QUADTREE-VISUALIZER
* @group Phi-CS-73
* @batch 2022
* @repo https://github.com/Amey-Thakur/QUADTREE-VISUALIZER
* @date 2021
* @license MIT
*
* Developed as part of the Phi Education Training (Milestone 2) and
* BE Major-Project @ Terna Engineering College, University of Mumbai.
*
* This program finds and displays all factors of a given integer.
* A factor is a number that divides evenly into another number.
*
* @return int Returns 0 on successful execution.
*/
#include <conio.h> /* Console I/O library for clrscr() and getch() (DOS/Turbo C specific) */
#include <stdio.h> /* Standard I/O library for printf and scanf functions */
/**
* @brief Finds and prints all factors of a number.
*
* Iterates from 1 to n/2 and prints all numbers that divide n evenly.
*
* @param n The number to find factors for.
* @return int Returns 0 (implicit).
*/
int findFactors(int n);
/**
* @brief Main function - Entry point of the program.
*
* Prompts the user to enter a number and displays all its factors.
*/
int main() {
int number; /* Input number to find factors for */
clrscr(); /* Clears the console screen (Turbo C specific) */
/* Prompt user to enter a number */
printf("Enter number:");
scanf("%d", &number);
/* Find and display all factors */
findFactors(number);
getch(); /* Wait for a key press before closing (Turbo C specific) */
return 0; /* Return 0 to indicate successful execution */
}
/**
* @brief Finds and prints all factors of a number.
*
* A factor of n is any integer i where n % i == 0.
* Only checks up to n/2 since no factor greater than n/2 can exist (except n
* itself).
*
* @param n The number to find factors for.
* @return int Returns 0.
*/
int findFactors(int n) {
int i;
/* Iterate from 1 to n/2 to find all factors */
for (i = 1; i <= n / 2; i++) {
/* Check if i is a factor of n */
if (n % i == 0) {
printf("%d\t", i);
}
}
return 0;
}