-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from thvardhan/master
add sum of N terms of GP in C
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|