{}
run-icon
main.c
#include <stdio.h> int main() { int fac, num; // fac = factor, num = number entered by user // Ask user to enter a number printf("Enter a number: "); scanf("%d", &num); // Display message printf("Factors of %d are: ", num); // Loop starts from 1 and goes till the number // Because a factor can never be greater than the number itself for (fac = 1; fac <= num; fac++) { // If num is divisible by fac, then fac is a factor if (num % fac == 0) { printf("%d, ", fac); // Print the factor } } return 0; // Program ends successfully }
Output