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