C Exercises: Read an integer and find all its divisor
C Basic Declarations and Expressions: Exercise-47 with Solution
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:

C programming Code Editor:
Previous: Write a C program to calculate the value of S where S = 1 + 3/2 + 5/4 + 7/8.
Next: Write a C program to read and print the elements of an array of length 7, before print replace every negative number, zero with 100.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join