Friday, March 17, 2023

C Programming. Factors of a given number.

 Factors of a given number.

// Program to compute the factors of a given number.

#include<stdio.h>

int main() {
    int n, i;
    printf("Enter a number : ");
    scanf("%d", &n);
    printf("The factors of %d is : \n", n);
    for (i=1; i<=n; i++){
        if (n%i == 0){
            printf("%d ", i);
        }
    }
    return 0;
}


Output :
Enter a number : 12 The factors of 12 is : 1 2 3 4 6 12

No comments:

Post a Comment

Selection Sort Using C programming.

Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the un...