Skip to content
Merged
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
4 changes: 4 additions & 0 deletions C/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

29 changes: 29 additions & 0 deletions C/program-36/program.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>

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;
}
Binary file added C/program-37/a.out
Binary file not shown.
32 changes: 32 additions & 0 deletions C/program-37/program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Program to find the fibonacci sequnce
*/

#include<stdio.h>
#include<stdlib.h>

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;
}
Binary file added C/program-38/a.out
Binary file not shown.
32 changes: 32 additions & 0 deletions C/program-38/program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Program to find the factorial of a number using recursion
*/

#include<stdio.h>
#include<stdlib.h>

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;
}
Binary file added C/program-39/a.out
Binary file not shown.
32 changes: 32 additions & 0 deletions C/program-39/program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Program to find the GCD of a number using recursion
*/

#include<stdio.h>
#include<stdlib.h>

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;
}