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