Find all divisors of a given integer
Find all divisors of a given integer
Write a C program that finds all the divisors of an integer.
Pictorial Presentation:
Sample Solution:
C Code:
#include <stdio.h>
int main() {
int x, i;
// Get an integer input from the user
printf("\nInput an integer: ");
scanf("%d", &x);
// Print all the divisors of x
printf("All the divisors of %d are: ", x);
for(i = 1; i <= x; i++) {
if((x%i) == 0){
printf("\n%d", i);
printf("\n");
}
}
return 0;
}
Sample Output:
Input an integer: 45 All the divisor of 45 are: 1 3 5 9 15 45
Flowchart:
For more Practice: Solve these Related Problems:
- Write a C program to find all the prime divisors of a given integer.
- Write a C program to count the total number of divisors of a user-entered integer.
- Write a C program to list all divisors of a given integer in both ascending and descending order.
- Write a C program to calculate the sum of all divisors of a given integer.
Go to:
PREV : Compute series sum S=1+3/2+5/4+7/8.
NEXT : Replace negatives and zeros in an array with 100, then print.
C programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.