Explore BrainMass

Explore BrainMass

    Files in C-programming, factorial

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    1. Files can be used to store data. There is a function called feof() in standard C library to detect end of file condition. Assume that the input file contains simplified census data; each line contains a record and each record has name, sex, and age in a specific city. Write the pseudocode to find % of males, % of females, % of children (i.e. <17 years old), % of adults (ages 18 to 54), and % of elderly citizens (ages 55 and above).
    2. Assuming that n is an integer argument, write a function to compute factorial(n) where

    factorial(n) = 1, when n = 1
    = factorial(n-1) * n if n > 1

    © BrainMass Inc. brainmass.com December 24, 2021, 6:09 pm ad1c9bdddf


    Solution Preview

    You can use any of the:

    int factorial (int n) ;
    int factorial1 (int n) ;


    However, recursive version:

    int factorial1 (int n) ;

    is not memory efficient.

    int factorial (int n) ;

    for efficient ...