C Program to display factors of a number

Program:

#include <stdio.h>

void main()

{

    int num, i;

    

    printf("Enter a positive integer: ");

    scanf("%d", &num);

    printf("Factors of %d are: ", num);

    

    for (i = 1; i <= num; ++i)

    {

        if (num % i == 0)

        {

        printf("%d ", i);

        }

    }

}


Output:

Enter a positive integer: 10

Factors of 10 are: 1 2 5 10 


Drafted on 🌏 by,

Jal


peace

Comments

Popular posts from this blog

C program to read and display book information using structure

Count positive, negative and zero values in an array

Maximum value from array