cc

#include <stdio.h>

int main() {
    int number, i;
    printf("Enter a positive integer: ");
    scanf("%d", &number);

    printf("Factors of %d are: ", number);
    for (i = 1; i <= number; ++i) {
        if (number % i == 0) {
            printf("%d ", i);
        }
    }

    return 0;
}

Explanation:

  • #include <stdio.h>: Includes the standard input-output header file for input/output functions.
  • int main() { ... }: The main function where the program execution starts.
  • int number, i;: Declares two integer variables number and i.
  • printf("Enter a positive integer: ");: Displays a message asking the user to enter a positive integer.
  • scanf("%d", &number);: Reads an integer input from the user and stores it in the number variable.
  • printf("Factors of %d are: ", number);: Displays a message indicating the factors of the entered number.
  • for (i = 1; i <= number; ++i) { ... }: Starts a loop that iterates from 1 to the entered number.
    • if (number % i == 0) { ... }: Checks if the current value of i is a factor of number using the modulo operator %.
      • printf("%d ", i);: If i is a factor of number, it prints the value of i.
  • return 0;: Indicates the successful execution of the program. The main function returns 0 to the operating system.