Stefan
for this : S = 1/(1*2) + 1/(2*3) + 1/(3*4) + ... + 1/(n * n+1) is this correct : #include <iostream> #include <stdio.h> using namespace std; int main(){ int a=1, b=2, sum, n; cin >> n; for(int i=0; i<n; i++){ sum += 1/(a*b); a++; b++; } cout << sum; }
first you used integer division with truncate to integers second this is https://math.stackexchange.com/questions/1027110/infinite-series-sum-1-nn1 inverse of https://en.wikipedia.org/wiki/Pronic_number
Al
I have installed minGW on my windows
run code . from the mingw terminal
Al
plus sum is a float
Al
or a double
mahdi13
or a double
mahdi akhbar, [24.12.20 15:13] #include <iostream> using namespace std; int main(){ int n; float i=1, j=2; float sum; cin >> n; n++; for(int a=1; a<n; a++){ sum = 1/(i*j); i++; j++; } cout << sum; return 0; }
Nurullah
hi
Nurullah
how can I do the Gets function in 2 dimensions
imran
can someone teach me to make mini project proposal?
Anonymous
much much easier
Anonymous
oooops its wrong
Anonymous
there it is
Anonymous
no wait fuk
mahdi13
oooops its wrong
yes bro there is *
mahdi13
no wait fuk
I did it
Anonymous
yeah it's ok
Anonymous
dunno man I come from py and the less lines the better even though you put the whole main and include
Anonymous
still ain't that much magic behind the algorithm
Anonymous
he's right tho
Crbala
hi all are there any guide available or any books available on how to connect to oracle db using cpp I prefer the env in linux I have worked with all file based one than oracle db before raising this query I have checked the stackoverflow and one sample code in github and occi guide but want to know are there any other documentation than this. Thanks in advance
Anonymous
Merry Christmas
!/usr
Hello
!/usr
# include <iostream> using namespace std; int fact(int c){     int factorial =1;     for(int i=0; i<=c; i++){         factorial*=i;     }     return factorial; } int binomial(int a, int b){     int value_n = fact(a);     int value_r = fact(b);     int value_diff = fact(a-b);     int coeff = value_n/(value_r*value_diff);     return coeff; } int main(){     cout<<"Enter the values of n and r"<<endl;     int n,r, result;     cin>>n>>r;     cout<<n<<r;     if(n>=r){         result = binomial(n,r);         cout<<result;     }     else{         cout<<"Valur of n must be greater than or equal to r"<<endl;     }     return 0; }
!/usr
Program to find out binomial coefficient But no output
!/usr
Can any body guide me where i m wrong?
Anonymous
# include <iostream> using namespace std; int fact(int c){     int factorial =1;     for(int i=0; i<=c; i++){         factorial*=i;     }     return factorial; } int binomial(int a, int b){     int value_n = fact(a);     int value_r = fact(b);     int value_diff = fact(a-b);     int coeff = value_n/(value_r*value_diff);     return coeff; } int main(){     cout<<"Enter the values of n and r"<<endl;     int n,r, result;     cin>>n>>r;     cout<<n<<r;     if(n>=r){         result = binomial(n,r);         cout<<result;     }     else{         cout<<"Valur of n must be greater than or equal to r"<<endl;     }     return 0; }
I think it might get too big
Anonymous
The numbers could get too big
Anonymous
I ran it
Anonymous
no error
...
May be he is trying for larger numbers
Anonymous
When the number he entered is too large, it may be wrong
Al
# include <iostream> using namespace std; int fact(int c){     int factorial =1;     for(int i=0; i<=c; i++){         factorial*=i;     }     return factorial; } int binomial(int a, int b){     int value_n = fact(a);     int value_r = fact(b);     int value_diff = fact(a-b);     int coeff = value_n/(value_r*value_diff);     return coeff; } int main(){     cout<<"Enter the values of n and r"<<endl;     int n,r, result;     cin>>n>>r;     cout<<n<<r;     if(n>=r){         result = binomial(n,r);         cout<<result;     }     else{         cout<<"Valur of n must be greater than or equal to r"<<endl;     }     return 0; }
factoria multiply by 0 ... result is always 0
Al
init i to 1
...
init i to 1
In fact function
Anonymous
uha
Al
yep
Al
well i didnt read the rest by the way 😂
Al
coeff is an int
Al
should be a float or double
...
Will the binomial coefficient always an int?
Al
i see many errors here...
Al
a no
Al
sorry
!/usr
Will the binomial coefficient always an int?
But atleast it can show an output
Al
float or double
Al
you have a division
Al
  int coeff = value_n/(value_r*value_diff);
Al
this CANT be an int
Al
so the return type of the function
!/usr
Ya now i got the output Thank you so much guys😇😇
Al
👍
Al
ill sent you my paypal 😂
...
It can be int
!/usr
I would love to see a paypal account😂
!/usr
It can be int
Ya i got it Thank you😇
...
should be a float or double
Binomial is always an integer
olli
Will the binomial coefficient always an int?
In mathematics, the binomial coefficients are the positive integers that occur as coefficients in the binomial theorem. So, yes it is. Although it might overflow int fairly fast
Al
correect but the result of / operator in not
Al
is not
olli
correect but the result of / operator in not
Strictly speaking the type of the result returned by operator / depends on its parameters
Al
Strictly speaking the type of the result returned by operator / depends on its parameters
i dont agree with that ... but if you have a source to show i will read it
Al
and learn
Al
actually it looks is correct what you say
Al
from google
olli
i dont agree with that ... but if you have a source to show i will read it
For integral operands the / operator yields the algebraic quotient with any fractional part discarded http://eel.is/c++draft/expr.mul#4 Hence auto x = 7/2; // x is of type int with value 3 but auto x = 7.0/2; // x is 3.5
Iakovos
Hello guys! I ran into a problem trying to count comparisons of insertion sort in an array. https://pastebin.pl/view/dbb9f1b1 Any help is much appreciated!
olli
Hello guys! I ran into a problem trying to count comparisons of insertion sort in an array. https://pastebin.pl/view/dbb9f1b1 Any help is much appreciated!
Please state what did not go as you expected, otherwise here a guess In your case you allocate the memory for the array of size n before you initialize n. // which value of `n`? arr = (unsigned int*)malloc(n*sizeof(unsigned int)); // assign/initialize after use printf("Give array size: "); scanf("%d", &n);