Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9258755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:29:16+00:00 2026-06-18T12:29:16+00:00

I am attempting to re-write this bash function in C, but the a little

  • 0

I am attempting to re-write this bash function in C, but the a little unsure of how to convert this function into a C loop.

Here I have variables set. This I already have

n=10
r=4

This is where I get a little lost on how to re-write this. This seems to be calling the function with its own function and I pretty sure C will not do that (safely at least ) Also it does not need to be a function at all, I just need to plug in the same variables and have it come out with the same result.

factorial() {
if (($1)); then
    echo $(($1 * $(factorial $(($1-1)))))
else
    echo 1
fi
}

The last bit, is what would be the best way to express the code below in C? Would the bracketing in bash carry over?

result=$(($(factorial $n)/($(factorial $r)*$(factorial $(($n-$r))))))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:29:17+00:00Added an answer on June 18, 2026 at 12:29 pm

    It’s totally legal for C functions to call themselves – this is called recursion. In C, it would look like this:

    int factorial(int n) {
        if (n == 0) return 1;
        return n * factorial(n - 1);
    }
    

    You could also write this directly as a loop:

    int factorial(int n) {
        int result = 1;
        for (int i = 1; i <= n; i++) {
            result *= i;
        }
        return result;
    }
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to write a particular script that logs into a website. This specific
Is this possible? I am attempting to write a function for onmousedown that will
I attempting to write a simple JQuery search. This is what I have so
I am attempting to write this trigger but it is not working right. I
I have been attempting to write a VBA Script that can parse out other
I am attempting to write my first Dynamics Crm 2011 plugin. I have therefore
i'm attempting to write the result of the $x = [System.Net.Dns]::GetHostAddresses($name) statement into my
I'm attempting to write a simple query where I declare some variables and then
I'm attempting to write a bash script to parse out the following log file
I am attempting to write this html in haml so as to add an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.