bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_1 / practice-c / pc-ip-06.c

pc-ip-06.c (466B)


      1 /*
      2  * Question 6:
      3  * Write a program using a function to compute and display all factors of a given number.
      4  */
      5 
      6 #include <stdio.h>
      7 
      8 void printFactors(int);
      9 
     10 int main()
     11 {
     12     int n;
     13     printf("Enter the number: ");
     14     scanf("%d", &n);
     15     printFactors(n);
     16     return 0;
     17 }
     18 
     19 void printFactors(int n)
     20 {
     21     int i;
     22     printf("\nFactors of %d:", n);
     23     for (i = 1; i <= n; i++)
     24     {
     25         if (n % i == 0)
     26         {
     27             printf("  %d", i);
     28         }
     29     }
     30 }