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

  • Home
  • SEARCH
  • 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 8791073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:47:35+00:00 2026-06-13T22:47:35+00:00

I’m trying to find a solution(fix errors) in my programme which must count the

  • 0

I’m trying to find a solution(fix errors) in my programme which must count the binomial theorem from definition. Firstly I created the definition of “factorial” – “silnia”.

1) The algorithm determines the value of SN1 (n,k) of the definition. (newton function)

2) The algorithm determines the value of SN3 (n,k) recursively by the formula. (newton_rek function).

INPUT:
File name: In0101.txt

OUTPUT:
File name: Out0101.txt
In this file I want to save the values ​​calculated from the formulas.

EXAMPLE:
In0101.txt

8 2// n k 

Out0101.txt

n=8 k=2
SN1 = 28; count= 14

And there is an error I can’t fix. Does anybody can help me with this ?

MY CODE:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

long silnia(int a)
{
    long s;
    if (a == 0 || a == 1)
    {
        return 1;
    }
    else
    {
        s = 1;
        for (int i = 1; i <= a; i++)
        {
            s *= i;
        }
    }
    return s;
}

long newton(int n, int k)
{
    return silnia(n)/(silnia(k)*silnia(n-k));
}

unsigned long int newton_rek(long int n ,long int k)
{
    if ( n == k || k == 0 )
    {
        return 1;
    }

    if (k > n)
    {
        return 0;
    }

    else return newton_rek(n-1,k-1) + newton_rek(n-1,k);
}

int main()
{
    int n = 0;
    int k = 0;
    long funkcja1 = 0;
    long funkcja2 = 0;

    FILE *f = fopen("In0101.txt", "r+");    
    if (f == NULL)
    {
        printf("Nie udalo sie otworzyc pliku In0101.txt\n");
        return 1;
    }
    fread(n, sizeof(long), 1 , f);
    fread(k, sizeof(long), 1 , f);
    fclose(f);

    FILE *ff = fopen("Out0101.txt", "w+");    

    if (ff == NULL)
    {
        printf("Nie udalo sie otworzyc pliku Out0101.txt\n");
        return 1;
    }

    funkcja1 = newton(n,k);
    funkcja2 = newton_rek(n,k);
    fwrite(funkcja1, sizeof(long), 1 , ff);
    fwrite(funkcja2, sizeof(long), 1 , ff);
    fclose(f);

    return 0;
}
  • 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-13T22:47:36+00:00Added an answer on June 13, 2026 at 10:47 pm

    Your calculations both generate Pascal’s triangle. I have done a short test: http://ideone.com/jHA8EJ

    I think your problem is that you are not outputting correctly. You did not state the problem you were having in your question, so people suspected it was algorithmic due to your lack of description.

    I believe the problem is actually here:

    fwrite(funkcja1, sizeof(long), 1 , ff);
    fwrite(funkcja2, sizeof(long), 1 , ff);
    

    There’s two things wrong:

    1. You are not taking the address of the variables you are writing. That’s likely to cause a crash (which perhaps you might have mentioned);
    2. You are trying to write them as binary, but you seem to be expecting text.

    You should replace those calls with something like this:

    fprintf( ff, "%d %d\n", funkcja1, funkcja2 );
    

    As Daniel Fischer pointed out:

    The address thing also applies to reading the input file (and also the
    byte/text representation thing), furthermore fread gets the wrong size
    parameter.

    That is:

    fread(n, sizeof(long), 1 , f);
    fread(k, sizeof(long), 1 , f);
    

    Same two principles apply. You are reading binary values and you are doing it incorrectly. Instead, read text:

    int nvals = fscanf( f, "%d%d", &n, &k );
    

    You should test that nvals is 2, indicating that both values were read successfully.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.