Skip to content

Commit

Permalink
Merge pull request #74 from thvardhan/master
Browse files Browse the repository at this point in the history
add sum of N terms of GP in C
  • Loading branch information
BaReinhard authored Oct 4, 2017
2 parents b0341a1 + b0d2a9d commit a16e7c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions algebra/combinations/c/calculate_combinations.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>


long long int fact(int n){
if(n==1 || n==0)return 1;
return fact(n-1)*n;
}

long long int combination(int n,int r){
return fact(n)/(fact(r)*fact(n-r));
}

void main(){
int n,r;
printf("Enter N then R from nCr\n");
scanf("%d%d",&n,&r);
printf("Value of %dC%d is %ld",n,r,combination(n,r));
}
11 changes: 11 additions & 0 deletions algebra/sum_of_n_terms_of_gp/c/sumOfGP.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include<stdio.h>
#include<math.h>

void main(){
float n,r,a,sum;
printf("Enter the first term of the GP then Common Ratio then number of terms.\n");
scanf("%f%f%f",&a,&r,&n);
sum=(a*(1-pow(r,n)))/(1-r);
printf("The sum of first %.0f terms is %f\n",n,sum);
}

0 comments on commit a16e7c1

Please sign in to comment.