0% found this document useful (0 votes)
58 views1 page

Triunghiul Lui Pascal

The document contains C++ code that calculates binomial coefficients and writes them to a text file. It prompts the user to input values for n and k, generates the binomial coefficients from 0 to n choosing k at a time using a recursion formula, and writes the results to a file.

Uploaded by

Adrian Hagiu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views1 page

Triunghiul Lui Pascal

The document contains C++ code that calculates binomial coefficients and writes them to a text file. It prompts the user to input values for n and k, generates the binomial coefficients from 0 to n choosing k at a time using a recursion formula, and writes the results to a file.

Uploaded by

Adrian Hagiu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;


#include <fstream>
#include <stdio.h>
#define max 20
void main()
{
int n,k,C[max][max],i,j;
et: cout<<" Dati numarul n "; cin>>n;
cout<<" Dati numarul k,mai mic,cel mult egal cu "<<n<<" k= "; cin>>k;
ofstream scriu;
scriu.open("Combinari.txt");
scriu<<n<<" "<<k<<endl<<endl;
scriu<<"****************************************************************
****"<<endl<<endl;
C[0][0]=1;
scriu<<C[0][0]<<endl<<endl;
for(i=1;i<=n;i++)
{
for(j=0;j<=i;j++)
{
if(j==0 ||j==i) C[i][j]=1;
else C[i][j]=C[i-1][j-1]+C[i-1][j];
scriu<<C[i][j]<<" ";
}
scriu<<endl<<endl;
}
scriu<<"****************************************************************
****"<<endl<<endl;
cout<<"Am generat triunghiul"<<endl;
cout<<" Combinari de "<<n<<" luate cate"<<k<<"este="<<C[n][k]<<endl;
scriu<<endl<<"Combinari de "<<n<<"luate cate "<<k<<"este="<<C[n][k]<<end
l<<endl;
scriu.close();
getchar();
return;
}

You might also like