IP-06.c (803B)
1 /* Write a program using a function to compute and display all factors of a given number. */ 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 void display_factors(int); 7 8 int main() 9 { 10 int num, i; 11 printf("Please enter the number to get the factors from it : "); 12 scanf("%d", &num); 13 display_factors(num); 14 return 0; 15 } 16 17 void display_factors(int num) { 18 int temp = abs(num); 19 int i; 20 21 if (temp == 0) 22 { 23 printf("\n0 has infinitely many factors (all integers)."); 24 exit(1); 25 } 26 27 printf("\nThe factors of ' %d ' is :- ", num); 28 printf("\nPositive : "); 29 for (i = 1; i <= temp; i++) 30 if (temp % i == 0) 31 printf(" %d", i); 32 printf("\nNegative : "); 33 for (i = 1; i <= temp; i++) 34 if (temp % i == 0) 35 printf(" %d", -i); 36 }