Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCD function simplified #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
20 changes: 20 additions & 0 deletions GCD.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
int main()
{
int n1, n2, i, gcd;

printf("Enter two integers: ");

scanf("%d %d", &n1, &n2);

for(i=1; i <= n1 && i <= n2; ++i)
{
// Checks if i is factor of both integers

if(n1%i==0 && n2%i==0) //here if i on division gives 0 as remainder in both cases that means it is definetely GCD
gcd = i;
}
printf("G.C.D of %d and %d is %d", n1, n2, gcd); //prints the GCD value

return 0;
}
50 changes: 50 additions & 0 deletions bst.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<stdio.h>
#include<stdlib.h>//for malloc memory declaration
int bs(int *ptr1);

int main()
{
int *ptr,n,i;

ptr=malloc(n*sizeof(int));//makes an array of n blocks;

printf("Enter the size of an array\n");

scanf("%d",&n);
printf("Enter the array\n");//message for array entry

for(i=0;i<n;i++)
{
scanf("%d",(ptr+i));
}
bs(ptr);//bubble sort function is called by passing ptr to be point by pointer ptr1 in bs function
return 0;
}


int bs(int *ptr1)
{
int temp,round,l,i;

for(l=0;*(ptr1+l)!='\0';l++);//getting the size of an array

for(round=1;round<=l-1;round++)
{
for(i=0;i<=l-round-1;i++)
{
if(*(ptr1+i)>*(ptr1+i+1))//comparision for sorting
{
temp=*(ptr1+i); //swapping

*(ptr1+i)=*(ptr1+i+1);
*(ptr1+i+1)=temp;
}
}

}
for(i=0;i<l;i++) //printing of sorted value
{
printf("\t%d",*(ptr1+i));
}
return 0;
}
49 changes: 49 additions & 0 deletions linked.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include<stdio.h>
#include<stdlib.h>


struct node{ //structure declared
int data;
struct node *ptr;
};

int main()
{
struct node *first=NULL;//Assings null initially

struct node *second=NULL;//Assings null initially

struct node *third=NULL;//Assings null initially

first=malloc(sizeof(struct node));

second=malloc(sizeof(struct node));

third=malloc(sizeof(struct node));

first->data=22;//filling 22 into data

first->ptr=second;

second->data=23;//filling 23 into data

second->ptr=third;

third->data=24;//filling 24 into data

third->ptr=NULL;

printlist(first);

return 0;
}
int printlist(struct node *n)

{
while(n!=NULL)
{
printf("\t%d",n->data);//printing of data
n=n->ptr;
}
return 0;
}