bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

external_6.c (487B)


      1 // 6. Write a program to compute the factors of a given number.
      2 
      3 #include<stdio.h>
      4 
      5 void factor(int);
      6 
      7 int main() {
      8     int n;
      9     printf("Enter a number: ");
     10     scanf("%d", &n);
     11     factor(n);
     12     return 0;
     13 }
     14 
     15 void factor(int n) {
     16     int i;
     17     printf("\nThe factors of %d = ", n);
     18     if(n == 0) {
     19         printf("Infinite.");
     20         return;
     21     }
     22     if (n < 0) n = -n;
     23     for(i = 1; i <= n; i++) {
     24         if(n % i == 0) {
     25             printf("%d  %d  ", i, -i);
     26         }
     27     }
     28 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror