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
2 changes: 1 addition & 1 deletion c/1darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ int main(){

printf("Sum=%d",sum);
return 0;
}
}
2 changes: 1 addition & 1 deletion c/2darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ int main(){
}
}
return 0;
}
}
Binary file added c/a.out
Binary file not shown.
2 changes: 1 addition & 1 deletion c/callByRef.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ void callByRef(int *x,int *y){
*y=*t;
printf("From call by value\n");
printf("x=%d\ty=%d\n",*x,*y);
}
}
2 changes: 1 addition & 1 deletion c/cylinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ void cylinder(float r, float h, float *csa, float *tsa, float *vol){
*csa = 2*r*h*PI;
*tsa = 2*r*(h+r)*PI;
*vol = r*r*h*PI;
}
}
2 changes: 1 addition & 1 deletion c/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ int main(){
//printing data
printf("%c %d %f %lf",ch,i,f,d);
return 0;
}
}
2 changes: 1 addition & 1 deletion c/empstruct.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ int main(){
printf("\nHighest Earner Detail\n");
printf("Name: %s\nPost: %s\nSalary: %.2f\n",high.name,high.post,high.salary);
return 0;
}
}
3 changes: 2 additions & 1 deletion c/forloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ int main(){
int i,n;

//reading value of n
printf("Enter n: ");
scanf("%d",&n);

//for loop
for(i=1;i<=n;i++){
printf("%d\n",i);
}
return 0;
}
}
2 changes: 1 addition & 1 deletion c/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
int main(){
printf("Hello World");
return 0;
}
}
Binary file added recursion/a.out
Binary file not shown.
30 changes: 27 additions & 3 deletions recursion/gcd.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
#include <stdio.h>

//recursive function for gcd of two numbers.
int gcd(int x, int y);

//iterative function for gcd of two numbers.
int gcd_iter(int u , int v);
int main(){
int a, b, g;
int a, b, g, f;

printf("Enter a and b:\n");
scanf("%d%d", &a, &b);

//gcd
g = gcd(a, b);

//gcd_iter
f=gcd_iter(a, b);

//in case g is negative, then convert it into positive
if(g < 0){
g *= -1;
}

//in case f is negative, then convert it into positive
if(f < 0){
f=f*(-1);
}

//output
printf("GCD(%d, %d) = %d\n", a, b, g);
printf("Recursive GCD(%d, %d) = %d\n", a, b, g);
printf("Iterative GCD(%d, %d) = %d\n", a, b, f);
return 0;
}

int gcd(int x, int y){
if(y == 0) return x;
else gcd(y, x%y);
}
}


int gcd_iter(int u, int v){
int t;
while (v) {
t = u;
u = v;
v = t % v;
}
return u < 0 ? -u : u; /* abs(u) */
}
2 changes: 1 addition & 1 deletion recursion/towerOfHanoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ void t(int n, char beg, char aux, char end){
t(1, beg, aux, end);
t(n-1, aux, beg, end);
}
}//t() ends here
}//t() ends here