diff --git a/C/README.md b/C/README.md index d837d3c1..5281951b 100644 --- a/C/README.md +++ b/C/README.md @@ -37,4 +37,8 @@ | Program-33 | Program on Arithematic operation using pointers | | Program-34 | Program to determine whether the matrix is a triangular matrix. First, you will be given N, which is the size of the matrix. Then you will be given N rows of integers, where each row consists of N integers separated by spaces. If the input matrix is triangular, then print yes. Otherwise, print no. | | Program-35 | Program where you are given a sequence of non-negative integers terminated by -1. You have to output 1 if there are atleast 2 distinct elements in the sequence and 0 if the sequence consists of only 1 integer. Note that -1 is not part of the sequence. The sequence is not necessarily sorted. | +| Program-36 | Program to output the number of distinct elements in the sorted sequence | +| Program-37 | Program to find the fibonacci sequnce using recursion | +| Program-38 | Program to find the factorial of a number using recursion | +| Program-39 | Program to find the GCD of a number using recursion | diff --git a/C/program-36/program.c b/C/program-36/program.c new file mode 100644 index 00000000..9d823305 --- /dev/null +++ b/C/program-36/program.c @@ -0,0 +1,29 @@ +/* + +You are given a sorted (either in the increasing or in the decreasing order) sequence of numbers, ending with a -1. You can assume that are at least two numbers before the ending -1. + +Let us call the sequence x0 x1 ... xn -1. + +You have to output the number of distinct elements in the sorted sequence. + +Kindly do not use arrays in the code. + +*/ + +#include +#include + +int main() +{ + int count=0,n=0,m; + while(n!=-1) + { + scanf("%d",&n); + if(m!=n) count++; + else continue; + m=n; + + } +printf("%d",count-1); + return 0; +} diff --git a/C/program-37/a.out b/C/program-37/a.out new file mode 100755 index 00000000..2dff926d Binary files /dev/null and b/C/program-37/a.out differ diff --git a/C/program-37/program.c b/C/program-37/program.c new file mode 100644 index 00000000..4a63c87c --- /dev/null +++ b/C/program-37/program.c @@ -0,0 +1,32 @@ +/* +Program to find the fibonacci sequnce +*/ + +#include +#include + +int fib(int n) +{ +int f; + + if(n==0 || n==1) + { + + return ; + } + else + { + f=fib(n-2)+fib(n-1); + } + + +} + +int main() +{ + int n; + printf("Enter the number of terms\n"); + scanf("%d",&n); + printf("Fibonacci series=%d \n",fib(n)); + return 0; +} diff --git a/C/program-38/a.out b/C/program-38/a.out new file mode 100755 index 00000000..0bb435f1 Binary files /dev/null and b/C/program-38/a.out differ diff --git a/C/program-38/program.c b/C/program-38/program.c new file mode 100644 index 00000000..02f4e88d --- /dev/null +++ b/C/program-38/program.c @@ -0,0 +1,32 @@ +/* +Program to find the factorial of a number using recursion +*/ + +#include +#include + +int fact(int n) +{ +int f; + + if( n==1) + { + + return ; + } + else + { + f=n*fact(n-1); + } + + +} + +int main() +{ + int n; + printf("Enter the number \n"); + scanf("%d",&n); + printf("Factorial of a number =% d \n",fact(n)); + return 0; +} diff --git a/C/program-39/a.out b/C/program-39/a.out new file mode 100755 index 00000000..4ebdcb8d Binary files /dev/null and b/C/program-39/a.out differ diff --git a/C/program-39/program.c b/C/program-39/program.c new file mode 100644 index 00000000..1d0f60f9 --- /dev/null +++ b/C/program-39/program.c @@ -0,0 +1,32 @@ +/* +Program to find the GCD of a number using recursion +*/ + +#include +#include + +int gcd(int a,int b) +{ +int f; + + if( b!=0) + { + + return gcd(b,a%b);; + } + else + { + return; + } + + +} + +int main() +{ + int a,b; + printf("Enter the two numbers\n"); + scanf("%d%d",&a,&b); + printf("GCD of %d & %d is = %d \n",a,b,gcd(a,b)); + return 0; +}