Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions C/binomial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<stdio.h>
int main()
{
int k,n;
printf("Enter the value of n & k\n");
scanf("%d%d",&n,&k);
int c[n+1][k+1];
for(int i=0;i<=n;i++)
{
for(int j=0;j<=k;j++)
{
c[i][j]=0;
}
}
for(int i=0;i<=n;i++)
{
c[i][0]=1;
c[i][i]=1;
}
for(int i=2;i<=n;i++)
{
for(int j=1;j<=i-1;j++)
{
c[i][j]=c[i-1][j-1]+c[i-1][j];
}
}
printf("The binomial coefficient of C(%d,%d) is %d\n",n,k,c[n][k]);
return 0;
}
38 changes: 38 additions & 0 deletions C/rec_lin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//Program for Recursive Linear Search

#include<stdio.h>

int rec_lin(int arr[], int low, int high, int key);

int main()
{
int n, key, result = 0;
printf("Enter the size of the array\n");
scanf("%d",&n);
int array[n];
printf("Enter the elements of the array\n");
for(int i=0;i<n;i++)
{
scanf("%d",&array[i]);
}
printf("Enter the element to be searched\n");
scanf("%d",&key);
result = rec_lin(array, 0, n-1, key);
(result == -1) ? printf("Element %d not found in the array\n", key)
: printf("Element %d found in the index %d",key, result);
return 0;
}

int rec_lin(int arr[], int low, int high, int key)
{
if(high < low)
return -1;
else if(arr[low] == key)
return low;
else if(arr[high] == key)
return high;
else
rec_lin(arr, low+1, high -1, key);
}